How to make a filter for .txt files?
I wrote something like this but it has an error:
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
int retval = chooser.showOpenDialog(null);
String yourpath = "E:\\Programy Java\\Projekt_SR1\\src\\project_sr1";
File directory = new File(yourpath);
String[] myFiles;
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File directory, String fileName) {
return fileName.endsWith(".txt");
}
};
myFiles = directory.list(filter);
if(retval == JFileChooser.APPROVE_OPTION)
{
File myFile = chooser.getSelectedFile();
}