Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

transferring large files

843793Jun 1 2006 — edited Jun 13 2006
Hi,

I have to transfer a file from client to the server, its working fine as long as the file size is small.
but when the file size increases it is giving me this error.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

so what exactly shud i do to transfer files of huge size.
how do i break it down and into small chunks and send it to the server

what is the modification required in the following code:

byte[] buf = new byte[1024];
BufferedInputStream bin = null;
ByteArrayOutputStream bout = null;

try {
FileInputStream fis = new FileInputStream( zipFile );
bout = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len = 0;
while( (len = fis.read(b, 0, 1024) ) != -1 ) {
bout.write( b, 0, len );
}
System.out.println("Fis available? 0 if yes : 1 if No "+fis.available());
bout.flush();

fileArray = bout.toByteArray();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2006
Added on Jun 1 2006
11 comments
423 views