aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 2771
    
  10

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