You can try JFileChooser. Here is an example.
import java.io.*;
import javax.swing.*;
class GetFileType {
public static void main(String[] args){
JFileChooser chooser = new JFileChooser();
File file = new File("Hello.txt");
String fileTypeName = chooser.getTypeDescription(file);
System.out.println("File Type= "+fileTypeName);
}
}
This will output Text Document. If it is a MP3 file passed then the output will be MP3 Format Sound.