This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes QuizCard txt file - newline missing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "QuizCard txt file - newline missing" Watch "QuizCard txt file - newline missing" New topic
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
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

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: 37950
    
  22
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: 37950
    
  22
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: 37950
    
  22
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QuizCard txt file - newline missing
 
Similar Threads
New Quiz Card Builder/Player for Exam Study
QuizCard class not found. (Head First Java 2nd Ed)
Head First Java QuizCardBuilder not saving files correctly
Runtime Error in Program for Unknown Reasons
scope problem