wie mache ich jfilechooser nur .txt akzeptieren

Ich versuche, meinen Kontakt in meiner Tabelle zu speichern, aber filechosser setzt immer auf alle Dateien. kann ich es so einstellen, dass es nur .txt akzeptiert und es als Standard oder als einzige Option verwendet.

savecontact.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        JFileChooser filesave = new JFileChooser();
        int returnVal = filesave.showSaveDialog(Main.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                File file = filesave.getSelectedFile();

                PrintWriter os = new PrintWriter(file);
                os.println("");
                for (int col = 0; col < table.getColumnCount(); col++) {
                    os.print(table.getColumnName(col) + "\t");
                }
                os.println("");
                os.println("");

                for (int row = 0; row < table.getRowCount(); row++) {
                    for (int col = 0; col < table.getColumnCount(); col++) {
                        os.print(table.getColumnName(col));
                        os.print(": ");
                        os.println(table.getValueAt(row, col));
                    }
                    os.println("");
                }
                os.close();
                System.out.println("Done!");
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
});

Antworten auf die Frage(3)

Ihre Antwort auf die Frage