• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

copying a file

 
Smitha Vallaru
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20171
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Kevin Ott
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic