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 the text file, I am writing things in the file with
public Formatter x;
x.format("%s", "" + m.getPoints() + "\n");
Whenever I want to go to a new line in my text file, with \n, it wont go to a new line, it will just write it directly behind the int value. I tried doing both
x.format("%s", "" + m.getPoints() + "\n");
x.format("%s", "" + m.getStoreItem1Bought() + "\n");
and
x.format("%s%s", "" + m.getPoints() + "\n", "" + m.getBought() + "\n");
but, both will just write the boolean directly behind the int value, without starting a new line. Any help on this?
I am using Windows 7 Ultimate 64 bits, and my text editor is Eclipse, I am running all of the code with Eclipse too.
More specifically, I would recommend using:
x.format("%d%n%s%n", m.getPoints(), m.getStoreItem1Bought());
Use this instead:
public static String newline = System.getProperty("line.separator");
Both of this options work. Your problem is in how you format the output:
System.out.format("%s" + newline + "%s" + newline, "test1", "test2");
System.out.format("%s%n%s", "test1", "test2");
Output:
test1
test2
test1
test2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With