Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic