Get the File Type Description in Java

This short Java tutorial shows how to get the file type description for a specific file in Java. This description is how it would be displayed in the system file browser.

First, you will need to create a File object for the file type that you want to get the description of. If you do not have a file of that type, you can create a temporary file with extension you are interested in.

Once you have created a File object you will need to get an instance of the FileSystemView . Once you have an instance, you can call the getSystemTypeDescription() method passing it the file object you created for the file type.

File file = new File("c:/temp/logo.jpg");

FileSystemView fileSystemView = FileSystemView.getFileSystemView();
System.out.println(fileSystemView.getSystemTypeDescription(file));


0 comments:

Post a Comment