wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes newline character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "newline character" Watch "newline character" New topic
Author

newline character

Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
Hi everyone,

Does println add a newline character to the end of a line? That is, if I have a line that is 80 characters long, if I say println, will the line become 81 characters long, and therefore wrap on most Windows systems?

Katrina
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
Okay, it looks like this is the case!

Katrina
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
According to the API for PrintStream (System.out is a PrintStream object), the println() method will "Terminate the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n')."

However, the problem is that if your console is 80 characters wide and you write to the 80th character, many consoles will start a new line for you. Since you also start a new line, you get double spaced lines. The important thing is that different operating systems will behave differently, so don't depend on that behavior.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
Ok, so basically I need to decide what I want to do and make sure that is the behaviour I get - no matter which operating system I am on.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Right. Don't go and hard-code 80 (or 79 or 81) in your program because it's possible to reconfigure the Windows command prompt screen to have pretty much any width at all.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
In the xterm window i use, I can change the number of lines by changing the size of the window, but since the program specified that a line should be considered 80 characters long due to MS Windows defaults, that is what I was using.

Is there a cross-platform way of checking the number of characters a line will have?

Is there a point in making a

variable in a program this short where the value of line length is only used once?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newline character
 
Similar Threads
Need Printwriter help!!!!
How to store the newlines entered by enter key in textarea?
Inserting newline character
Arrays
BufferedWriter Problem