This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "new lines in unix/windows" Watch "new lines in unix/windows" New topic

new lines in unix/windows

Joe Busch

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?

Joe Ess

Joined: Oct 29, 2001
Posts: 8707

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

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
Similar Threads
Ports used by the application
How to start Tomcat?
Automating a process
Converting shell script to a batch file
using Runtime.exec() and the process exitValue = 1