[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Out of memory
Don't read the whole file all at once and don't writ it all at once. Limit
your buffer size to 2MB or something. Read and write chunks in a loop until
you get the whole file transferred.
From: "Jason R. Kretzer" <jason@OpinionOne.com>
To: "'email@example.com'" <firstname.lastname@example.org>
Subject: Out of memory
Date: Mon, 18 Nov 2002 13:28:41 -0500
I am using the following code to add a file to a jar. It works fine for
smaller files, but if the file is over 56MB, it throws and out of memory
exception. Any ideas on how I can keep this from happening?
private File jarFile;
private JarOutputStream jarOut;
private FileOutputStream fileOut;
jarFile = jarFile;
fileOut = new FileOutputStream(jarFile);
jarOut = new JarOutputStream(fileOut, man);
JarEntry entry = new JarEntry(name);
FileInputStream input = new FileInputStream(file);
byte buffer = new byte[(int) file.length()];
if (file.length() != input.read(buffer, 0, (int) file.length()))
throw new IOException("The amount of bytes read from the file "
+ "didn't match the file size for "
jarOut.write(buffer, 0, (int) file.length());
Add photos to your messages with MSN 8. Get 2 months FREE*.