Solved

PrintWriter discrepancy in Windows and Linux environments

Posted on 2006-07-13
5
322 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unix in java example 9 53
Java / Linux and Regular Expressions 11 70
stackato and cloud 4 69
object oriented programming comparison 5 54
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

910 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

21 Experts available now in Live!

Get 1:1 Help Now