*
The moose likes Java in General and the fly likes new lines in unix/windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "new lines in unix/windows" Watch "new lines in unix/windows" New topic
Author

new lines in unix/windows

Joe Busch
Greenhorn

Joined: Jan 07, 2005
Posts: 12
How can I write a carriage return and line feed to an ascii file such that it will be properly recognized on both unix and windows operating systems?

Thanks,
Joe
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8910
    
    8

They're different on both systems. Different on a Mac too. Check out this this topic for the platform-independent way to code, and avoid using applications that don't recognize other system's EOL markers (I'm looking at you, Windows Notepad).


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Connie Kamrowski
Greenhorn

Joined: Aug 15, 2004
Posts: 23
If you determine which system it is being opened by you could declare a public static final variable such as:

static final public String WINDOWS_EOL = "\r\n";
static final public String UNIX_EOL = "\n";

and then substitute these variables for the CHAR(10) or such commands at the line ends.


**How much deeper would the ocean be if Sponges didn't grow in it?**
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: new lines in unix/windows