如何将TextField导出为相同格式的文本文件?

时间:2018-10-25 12:48:41

标签: java textfield

String Hasil = TextHasil.getText();
        try (PrintWriter out = new PrintWriter("C:/Users/steve/Desktop/HasilDekripsi.txt")) {
            out.println(Hasil);
        }catch (FileNotFoundException ex) {        
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }        

1enter image description here

1 个答案:

答案 0 :(得分:1)

尝试替换换行符:

out.println(Hasil.replaceAll("\n","\n\n"));

OR

out.println(Hasil.replaceAll("\n","\r\n"));

您可以获得独立于平台的行分隔符:

System.getProperty("line.separator")System.lineSeparator();