Re: Copy files in java gives me out of memory error



Not sure why. The other day I worte a spell check that loads the
entire english language into memory, and I had no prolbems. The
follownig code works for me. Also it is probably faster than yours,
and works great with any type of file.

public static void makeCopy(File from, File to) throws IOException
{
if(!to.exists())
{
to.createNewFile();
}
InputStream in = new FileInputStream(from);
OutputStream out = new BufferedOutputStream(new
FileOutputStream(to));

int b;
while((b = in.read()) != -1)
{
out.write(b);
}
out.flush();
in.close();
out.close();
}
.



Relevant Pages