\n won't work, not going to a new line

后端 未结 5 806
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 02:48

I\'m creating a small program that saves a int value into a text file, saves it, and loads it when you start the program again. Now, I need 3 more booleans to be stored in t

5条回答
  •  我在风中等你
    2021-01-14 03:49

    Well your syntax is surely quite.. interesting. Why use the formatting method if you're just piece the string together anyways? Also since you nowhere say what stream you're using we have to guess a bit, but anyways.

    Anyways I'm betting that 1. you're using windows and 2. that the editor (I bet on notepad) you're using only reacts to \r\n since that's the correct newline for Windows. To fix this DON'T hardcode \r\n in your code but instead use %n and use the printf function correctly (ie don't piece the string together!).

    Otherwise if you really have to piece the string together:

    String newline = System.getProperty("line.separator");
    x.format("%s", "" + m.getPoints() + newline);
    

    will work.

提交回复
热议问题