save file with JFileChooser save dialog

后端 未结 3 845
我在风中等你
我在风中等你 2021-01-03 12:06

I have written a Java program that opens all kind of files with a JFileChooser. Then I want to save it in another directory with the JFileChooser save dialog, but it only sa

3条回答
  •  醉酒成梦
    2021-01-03 12:38

    Something like..

    File file = fc.getSelectedFile();
    String textToSave = mainTextPane.getText();
    BufferedWriter writer = null;
    
    try
    {
    writer = new BufferedWriter( new FileWriter(file));
    writer.write(textToSave);
    JOptionPane.showMessageDialog(this, "Message saved. (" + file.getName()+")",
    "ImPhil HTML Editer - Page Saved",
    JOptionPane.INFORMATION_MESSAGE);
    }
    catch  (IOException e)
    { }
    

提交回复
热议问题