This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes File readable on windows and linux? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "File readable on windows and linux?" Watch "File readable on windows and linux?" New topic

File readable on windows and linux?

Anupam Bhatt
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
i dont know if its the right forum but asking :

I am facing a issue, so need some clue. one of my tests[coded in java] reads a text file [which is in dos format]. Since the text file is in dos format the test fails on linux when it compares some content with the content of the file [it should pass actually as its the same content].

When i change the file format to unix mode, everything is fine.
However then the test wont pass on Windows [this is my guess and i think i am correct]

How can i make the test pass with both windows and linux ?

Joe Ess

Joined: Oct 29, 2001
Posts: 8713

Unix and Windows use different line separators. If you are using a method that utilizes the os-dependent line separator, like BufferedReader.readLine(), you will have problems trying to use the same file on different OS's.
Some solutions would be to parse the file for the line separator yourself or use something other than a plain text file (binary, XML, serialized collection, etc.).

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Consider Paul's rocket mass heater.
subject: File readable on windows and linux?
Similar Threads
dos output
passing an object to a method
difference between Java, VisualBasic & C
FTP Put a zip file that contains text files in Linux
ASCII encoding in WordPad