Mithilfe nachfolgendem Codes kann man abfragen ob ein File eine gewünschte Dateiendung hat. Sehr gut in Verbindung mit JFileChooser für Netbeans
File file = new File("/path/to/file/dummy.txt"); if (!file.getAbsolutePath().endsWith(".txt")) { String s = file.getAbsolutePath(); s = s.trim() + ".xml"; file = new File(s); }