I've been trying to copy a big file from one folder to another, and i got memory problems.
I finally decided to read part of the file and then write it to the destination: basically reading some, writting some, reading some , writting some.
Unfortunately, the destination file is bigger than the original file, and it seems, that it's copying more than it should.
This is the code:
Do you have an idea of what i may be doing wrong??
Well, kinda. I don't really understand the intermediate step of appending to a StringBuffer anyway, though. Because of this, your method will only work for text files, and even then, only for your platform's default encoding, because you haven't accounted for locale when converting from byte to String. Also, this is still quite slow and quite memory intensive. A good file-copy routine looks something like