Solved

PrintWriter discrepancy in Windows and Linux environments

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat administrtor 12 58
web project error add remove 1 27
java mysql insert application 14 25
Tagging and Merging on Branch 1 29
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

792 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