Re: Copy files in java gives me out of memory error
- From: Canned <user@xxxxxxxxxxxxxx>
- Date: Thu, 27 Dec 2007 01:47:40 +0100
Daniel Pitts schreef:
Use a FileInputStream, and a FileOutputStream, and copy a small amount
at a time (say 8k) using a byte array.
Thanks its working now, using a method to create backup instead of
another class. Anyway, while working with FileOutputStream I've noticed
that if Im doing this then it just run,
FileInputStream from = new FileInputStream(fromFile);
FileOutputStream to = new FileOutputStream(toFile);
byte[] buffer = new byte[BUFFER_SIZE];
int bytesWrite;
while ((bytesWrite = from.read(buffer)) != -1) {
to.write(buffer, 0, bytesWrite);
}
but if I'm assigning "from.read(buffer)" to byteWrite first, then the
apps freeze. Why can't I do this?
FileInputStream from = new FileInputStream(fromFile);
FileOutputStream to = new FileOutputStream(toFile);
byte[] buffer = new byte[BUFFER_SIZE];
int bytesWrite = from.read(buffer);
while (bytesWrite != -1) {
to.write(buffer, 0, bytesWrite);
}
.
- References:
- Copy files in java gives me out of memory error
- From: Canned
- Re: Copy files in java gives me out of memory error
- From: Daniel Pitts
- Copy files in java gives me out of memory error
- Prev by Date: Re: Casting
- Next by Date: Re: Copy files in java gives me out of memory error
- Previous by thread: Re: Copy files in java gives me out of memory error
- Next by thread: Re: Copy files in java gives me out of memory error
- Index(es):