To write a file with environmentally correct line endings, the recommended class is PrintWriter
. The println(String)
method will output the given string and the appropriate line ending to the output file.
Jon Skeet is right, though: Your problem isn't so much technical as figuring out which file format you need on which system. If a file is processed on a Windows system, it is expected that lines end in \r\n
; on Unix systems, just \n
.
All this is complicated even more when you use FTP to transfer files between different systems: ASCII mode will automatically translate line endings for you, binary will not.
Email is also not kind to text formats: Outlook frequently mutilates text files sent across system boundaries.
People here on SO know about this kind of stuff. Give us some more details to work with and we can propose solutions. But it will likely not be possible to write a file on one system that will be correctly read on any system.