Solved

PrintWriter discrepancy in Windows and Linux environments

Posted on 2006-07-13
5
321 Views
Last Modified: 2006-11-18
Hi guys,

I noticed that when I use the following code in a windows environment:

PrintWriter writeFile = new PrintWriter(new BufferedWriter(new FileWriter(outFile)), true);

there is no problem viewing the file in notepad.  However, after executing the following code in a unix environment, and then viewing it in Windows Notepad, the spacing becomes all scrambled.

My client only uses Notepad and is unable to use any other viewer. Wordwrap doesn't help.

Can someone offer advice as to how to write text to a file in a unix environment, and in Notepad, the spacing doesn't get all screwed up?

Joe
0
Comment
Question by:gogodna
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 43 total points
ID: 17105020
don't use PrintWriter, it uses the platforms eol character
instead use BufferedWriter directly and use windows eol explicitly.

0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 41 total points
ID: 17105607
In windows, the eol char is "\r\n".
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 41 total points
ID: 17106037
Your program is exhibiting the correct behaviour - it produces Windows text format on WIndows machines and Unix on Unix. If you want to view a text file produced for Unix on a Windows machine, use a decent text editor. Even Windows write.exe will not suffer the problem you mention
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now