Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

QuizCard txt file - newline missing

 
Dinesh Kumar Tadepalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or the Formatter methods which are copied to PrintWriter#printf, PrintWriter#format and String#format. Use the %n tag.
 
Dinesh Kumar Tadepalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most commonly used PrintWriter is called System.out.
 
Dinesh Kumar Tadepalli
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks everyone... i figured out how to use printWriter... it works then

thanks again
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic