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
Post a Comment