How to get the file extension in grails? -


i started working on grails , want know how extension of file. ex: test.txt. want check extension(txt)? clue?

here's way. using regular expression.

def filename = 'something.ext' def matcher = (filename =~ /.*\.(.*)$/)  if(matcher.matches()) {     def extension = matcher[0][1]      if(extension in ['jpg', 'jpeg', 'png']) {         // go         println 'ok'     } else {         println 'not ok'     } } else {     println 'no file extension found' } 

Comments

Popular posts from this blog

python - Alternative to referencing variable before assignment -

vb.net - How to ignore if a cell is empty nothing -

javascript - How to bind ViewModel Store to View? -