File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes println Vs newLine method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "println Vs newLine method" Watch "println Vs newLine method" New topic

println Vs newLine method

Ramakrishnan Ponmudi
Ranch Hand

Joined: Apr 20, 2004
Posts: 72
i am copy a file from one location to another. if i am using PrintWriter's
println() its working fine. when i am using newLine() all lines are printed in the same line itself.
why it is not working properly?

BufferedReader in = new BufferedReader(new FileReader(filePath + "\\" + fileName));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(pathName+ "\\" + fileName)));
String strLine = null;
while( (strLine=in.readLine())!= null)

BufferedReader in = new BufferedReader(new FileReader(filePath + "\\" + fileName));
BufferedWriter out = new BufferedWriter(new FileWriter(pathName+ "\\" + fileName));
String strLine = null;
while( (strLine=in.readLine())!= null) {
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
[RT]: i am copy a file from one location to another.

I would recommend you forget about Readers and Writers here, and use a FileInputstream and FileOutputStream instead. Or use a FileChannel. Oversimplfied examples are here and here. Using Readers and Writers can result in complications if you don't know the details of the character encoding to be used with a file, and possible complications with line separators when going from Unix to Windows or vice-versa. If you simply want to make an identical copy of a file, ignore these issues and copy the raw bytes - that's what FileInputStream, FileOutputStream, and FileChannel allow you to do.
[ November 30, 2005: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: println Vs newLine method
Similar Threads
does this look right?
PrintWriter can only write 130k?
File IO with Servlet
read file not include new line
formatting get lost after streaming