Java: how to write formatted output to plain text file

前端 未结 6 1709
粉色の甜心
粉色の甜心 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:28

    Use System.getProperty("line.separator") for new lines - this is the platform-independent way of getting the new-line separator. (on windows it is \r\n, on linux it's \n)

    Also, if this is going to be run on non-windows machines, avoid using \t - use X (four) spaces instead.

提交回复
热议问题