Java如何实现点击按钮弹出保存文件的选项

Swing中用JFileChooser选择路径保存文件

String ss = this.mailEditor.getText();
JFileChooser jfc = new javax.swing.JFileChooser();             
if(JFileChooser.APPROVE_OPTION == jfc.showSaveDialog(this)) {
    File saveFile = jfc.getSelectedFile();
    try {
        if(!saveFile.exists()){
             saveFile.createNewFile();
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter(saveFile));
        bw.write(ss);
        bw.close();
                
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}


你可能感兴趣的:(Java)