• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

copying a file

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to copy an xml file of 13KB to new file using File readers, BufferReader and FilerWriter. But its only copying 8kb. There is no logic just read each line from one file and copy it newly created file.

Can anybody let me know, is there size limitation for copying file while using File Readers. I have even tried giving size of FileReader and writer.

Thanks
Smitha.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, of course there isn't a limitation on the size of the files you can copy.

When you look at the output file, is it the same as the input file only with some data at the end missing? If so, then most likely you aren't closing your output writer.

But you would be better off copying the file using InputStreams and OutputStreams. If you don't plan to do anything with the data except copy it, there's no point in converting the bytes to chars and then back to bytes. And if you don't use the right charset for your Reader, you could even corrupt the data.
 
Smitha Vallaru
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow!that was pretty fast. you are right i was not closing the file. Actually i wast testing code and once i finalize I thought of closing and setting it null. But, I never thought it would cost me a day.

Thanks
Smitha.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also seems quite possible that you're not copying the file correctly. One common error would be failing to check the return value of a read(char[]) call to verify how many chars were really read. If you show the code you used to copyy the file, we can help identify possible problems.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are also certain obscure circumstances where files can't be copied with streams/readers/writers, e.g. Macintosh OS 9 files having resource forks. Trying to copy those with the java.io classes will result in truncated files.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could be that you're not copying the file correctly. Here is some example source code showing how you can copy a file:



This listing is posted at e1071. Copying One File to Another

There are many more java source code examples at
http://exampledepot.com
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic