I am developing a java application for which I need only .xml
files. Now I want to show only .xml
files in JFileChooser
whenever user wants to save a file or open a existing file.
Is this possible to show only .xml
files?
You can use JFileChooser API to achieve your task.
For Open only .xml file
// create a filechooser;
JFileChooser chooser = new JFileChooser(cwd);
FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter(
"xml files (*.xml)", "xml");
chooser.setDialogTitle("Open schedule file");
// set selected filter
chooser.setFileFilter(xmlfilter);
Also, go through javax.swing.filechooser.FileNameExtensionFilter.