Blog Archive

Java how get filename and/or extension

Its very easy to do with the help of Apache commons IO FilenameUtils. Please download the jar file from the Apache commons IO website - http://commons.apache.org/io/
String filenamewithExtension = "filename.ext";
String justFilename = FilenameUtils.removeExtension(filenamewithExtension);
String extension = FilenameUtils.getExtension(filenamewithExtension);