I am trying to write data into a text file using java. I have created a form and it should write the details entered by a SINGLE user in a single line(for an example, all the data entered by user1 should save in line number one and all the details entered by user2 should save in line number two). I have used escaped chracters but no good. Here is a part of my code
Please help me
Are you better than me? Then please show me my mistakes..
Where Linux uses just \n for line breaks, Windows officially uses the \r\n combination. Proper text editors can also handle \n, but Notepad isn't a proper text editor. Any \r or \n will be displayed as a little block (), and only \r\n is a line break.
That's why you usually shouldn't use \n directly when working with files that will be used on Windows. System.getProperty("line.separator") will return the proper String for this (so "\r\n" for Windows), and java.util.Formatter and the methods that use it (String.format, PrintStream.printf, etc) will use the proper String when you use "%n" in the pattern.
Glad you got that working! However, I think Rob's point was you should use System.getProperty("line.separator") to be platform independent. I often set a constant somewhere and then just use the constant from then on. Java's ability to run on multiple platforms without recompiling is one of its major benefits, but you have to sort of cooperate with it to make that work.