Monday, 26 August 2013

java- JFileChooser- Get the type of selected file by JFileChooser

java- JFileChooser- Get the type of selected file by JFileChooser

I am writing a program to select file from the JFileChooser. How can i get
the file type (e.g. is that file is ".txt" or ".html" of ".dat", etc.. ) i
have the following code. what should i have to add extra lines?
JFileChooser choice = new JFileChooser();
int option = choice.showOpenDialog(this);
if (option == JFileChooser.APPROVE_OPTION)
{
String path=choice.getSelectedFile().getAbsolutePath();
String filename=choice.getSelectedFile().getName();
System.out.println(path);
listModel.addElement(path);
System.out.println(filename);
}

No comments:

Post a Comment