This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

linebreaks

 
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
Mac Safari Java
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!