| Author |
QuizCard txt file - newline missing
|
Dinesh Kumar Tadepalli
Greenhorn
Joined: Jun 17, 2009
Posts: 15
|
|
HI, When I ran and saved some cards in the quiz card game of head first java, I observed that a new line character is not working and all my cards are on line. I checked my txt file and it didn open in new lines
the specific code where i wrote into a file is:
please point out the mistake.
thanks
|
 |
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2535
|
|
It probably is working, but your platform doesn't recognize "\n" as a line separator. A good thing to do for cross-platform compatibility is:
then
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
|
Or perhaps use a PrintWriter object and use the println(...) method when you want to write a String followed by a line terminator.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32596
|
|
|
Or the Formatter methods which are copied to PrintWriter#printf, PrintWriter#format and String#format. Use the %n tag.
|
 |
Dinesh Kumar Tadepalli
Greenhorn
Joined: Jun 17, 2009
Posts: 15
|
|
thanks for your suggestions, but the String sep = System.getProperty("line.seperator"); does not work too.
should i include or import any package?
how to write using printWriter methods?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32596
|
|
|
The most commonly used PrintWriter is called System.out.
|
 |
Dinesh Kumar Tadepalli
Greenhorn
Joined: Jun 17, 2009
Posts: 15
|
|
thanks everyone... i figured out how to use printWriter... it works then
thanks again
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32596
|
|
You're welcome
|
 |
 |
|
|
subject: QuizCard txt file - newline missing
|
|
|