• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

println Vs newLine method

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
out.println(strLine);

BufferedReader in = new BufferedReader(new FileReader(filePath + "\\" + fileName));
BufferedWriter out = new BufferedWriter(new FileWriter(pathName+ "\\" + fileName));
String strLine = null;
while( (strLine=in.readLine())!= null) {
out.write(strLine);
out.newLine();
}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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 ]
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic