Determining the type of a file using the extension (0)
August 6th, 2009 by Frank Niedermann, under Java.
This is how the type of a file can be determined using the extension of the file:
1 2 3 4 5 6 7 8 9 10 | public class FileType { public static void main(String[] args) { String fileName = "foo.pdf"; String extension = fileName.substring(fileName.lastIndexOf(".")); System.out.println("Extension: " + extension); if (fileName.equalsIgnoreCase(".pdf")) { System.out.println("It is a PDF-File."); } } } |