I am using Java SE 6.
My program reads several types of files: from dos to unix and ascii to unicode, and I have to make sure that the line separators for the output file match the input files.
As I do this, I read an example string with the BufferedReader read () function to find the first line separator and saved the line separator to String. That way, it can be used later when I need a new line.
I checked the Scanner class and noticed that possible line breaks might include the following:
\r\n \r \n \u2028 \u2029 \u0085
Is there a library for checking these characters? Or, even better, is there a library function to check what the input line separator looks like?
Are there any other ways around this?
EDIT: If possible, I would like to use the standard Java API instead of third-party libraries, but all suggestions are welcome.
EDIT: Just to clarify.
1) Input files do not depend on where this program works. For example, if I run this program in Dos, I can still get the Unix input file.
2) My goal is not to read each line with line separators - it's simple. I really need to write an output file with the same line separators as the input file. For example, if I run this program in Dos and I get a Unix input file, I want to be able to write an output file with Unix line separators. That's why I ask if there is a standard API for detecting line separators based on input files, and not for starting the OS.
Thanks.
java
Russell
source share