Solved

PrintWriter discrepancy in Windows and Linux environments

Posted on 2006-07-13
5
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

617 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