This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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

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: 9137

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

[How To Ask Questions On JavaRanch]
Have you checked out Aspose?
subject: File readable on windows and linux?
It's not a secret anymore!