File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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: 9169

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).

[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?**
I agree. Here's the link:
subject: new lines in unix/windows
It's not a secret anymore!