• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

linebreaks  RSS feed

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

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

Thanks!
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\r makes the whole line dissappear
Anyways, if i'm reading characters in, \r\n are 2 charaters right?
 
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread...

http://www.coderanch.com/t/399847/java/java/when-why-we-FF-CR
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this helps: http://jqa.tmorris.net/GetQAndA.action?qids=62&showAnswers=true
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!