wood burning stoves*
The moose likes Beginning Java and the fly likes linebreaks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "linebreaks" Watch "linebreaks" New topic
Author

linebreaks

Csaba Kassitzky
Ranch Hand

Joined: Nov 29, 2005
Posts: 38
Hi everyone!

Someone mentioned \n and \r are the linebreaks.
Can "\n\r" be used both? Does this count as one linebreak?

Thanks!
C Broussard
Greenhorn

Joined: Jun 18, 2004
Posts: 28
i usually just do "\r\n"

not sure if switching works it.. you can write a quick static main and test it though...

public class test{

public static void main(String[] args){
System.out.print(" 1) this is a \r\n test ");
System.out.print(" 2) this is a \n\r test ");
System.out.print(" 3) this is a \n test ");
System.out.print(" 4) this is a \r test ");

}
}

just compile and run.


www.binaryfrost.com
Csaba Kassitzky
Ranch Hand

Joined: Nov 29, 2005
Posts: 38
\r makes the whole line dissappear
Anyways, if i'm reading characters in, \r\n are 2 charaters right?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See this thread...

http://www.coderanch.com/t/399847/java/java/when-why-we-FF-CR


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
When reading in a text file, it's more common to read it in one line at a time, versus one character at a time. For the former, BufferedReader has the method readLine:

Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.

The string readLine returns does not include any terminator.

But if you are reading one character at a time, "\r\n" is two chars.


There is no emoticon for what I am feeling!
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
See if this helps: http://jqa.tmorris.net/GetQAndA.action?qids=62&showAnswers=true


Tony Morris
Java Q&A (FAQ, Trivia)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: linebreaks