Archive for August, 2009

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.");
		}
	}
}

Tagged with , , , .