Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PrintWriter discrepancy in Windows and Linux environments

Posted on 2006-07-13
5
Medium Priority
?
354 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 172 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 164 total points
ID: 17105607
In windows, the eol char is "\r\n".
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 164 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

971 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