wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
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: 8843
    
    7

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?**
 
Consider Paul's rocket mass heater.
 
subject: new lines in unix/windows
 
Similar Threads
using Runtime.exec() and the process exitValue = 1
Ports used by the application
Converting shell script to a batch file
Automating a process
How to start Tomcat?