Java: how to write formatted output to plain text file

前端 未结 6 1717
粉色の甜心
粉色の甜心 2021-01-18 18:24

I am developing a small java application. At some point i am writing some data in a plain text file. Using the following code:

Writer Candidateoutput = null;         


        
6条回答
  •  滥情空心
    2021-01-18 19:15

    You can use line.separator system property to solve your issue.

    E.g.

    String separator = System.getProperty("line.separator");
    
    Writer Candidateoutput = null;
    File Candidatefile = new File("Candidates.txt"),
    Candidateoutput = new BufferedWriter(new FileWriter(Candidatefile));
    Candidateoutput.write(separator + " Write this text on next line");
    Candidateoutput.write("\t This is indented text");
    Candidateoutput.close();
    

    line.separator system property is a platform independent way of getting a newline from your environment.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题