I have a created text file in unix enviroment using java code.
For writing the text file i am using java.io.FileWriter and BufferedWriter. and for newline after each row i am using bw.write("\r\n") method. (where bw is object of BufferedWriter) and sending that text file by attaching in mail from unix environment itself to other environments like(mainframe,windows)
My issue is, if my client's download the text file in Mainframe system, they found that in text file a "special character"(like small rectangular box) presenting and data not properly aligned.
bw.write("\r\n") is not working i think so..(but working fine in windows).
I want same text file alignment as it is in unix environment and without any special
character symbol too, if they opened the text file in mainframe ,windows environments
or any other enviroments.
How to resolve the problem. Thanks for your help in advance.
pasting my piece of java code here for your reference..(running java code in unix
environment)
File f = new File(strFileGenLoc);
BufferedWriter bw = new BufferedWriter(new FileWriter(f, false));
rs = stmt.executeQuery("select * from jpdata");
while ( rs.next() ) {
bw.write(rs.getString(1)==null? "":rs.getString(1));
bw.newLine();
}
Contrary to your claim, your code clearly isn't writing "\r\n" after each line. It's calling BufferedWriter.newLine() which uses the current platform's default line separator (unless you explicitly set the line.separator system property). On Unix systems this will be "\n".
Now, you need to think about what you want the result to be on the target systems where it will be read. For Windows, that means you should explicitly write "\r\n"... I don't know about the mainframes you mention though - you'd need to give more details.
Note that the fact that there are different line separators available means that no one text file will be universally suitable. Many text editors on different platforms cope with any line separator... but there will always be some that don't :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With