aspose file tools*
The moose likes Java in General and the fly likes Download large files in RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Download large files in RMI" Watch "Download large files in RMI" New topic
Author

Download large files in RMI

Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 44
Hi.,

I have a file in my server which is of huge size. Need to download that from my client.
Below is the method i use to read to do the same.

byte[] bytes = null;
File report = new File(absolutePath);
StringBuffer os = new StringBuffer();

if (report != null && report.exists() && report.isFile()) {
BufferedInputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(report));
bytes = new byte[(int) report.length()];
int buf = 1024;
int i=0;
while(true){

if(input.available() <= 1024){
input.read(bytes , buf*i, input.available());
break;
}
else
{
input.read(bytes , buf*i, buf);
}
i++;
}
....
.....
but it fails here bytes = new byte[(int) report.length()];

because the length of the file is too big.

Can you please suggest some other way to read large files in java.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11408
    
  16

What do you mean by "but it fails...because the length of the file is too big"? Does it die and do nothing? Do you get an error message and if so, what - EXACTLY - does it say? Does it do something else, and if so, what?

How do you know that is it failing because the file is too big?

You need to tell the details if you want any kind of reasonable help.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5


Why are you doing that? Why not simply write to a temp file as you get buffer loads - no reason to try to keep the whole thing in memory.

Bill
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 44
getting this error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

How do i get the temp file to my client side.?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
William Brogden wrote:Why not simply write to a temp file as you get buffer loads - no reason to try to keep the whole thing in memory.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download large files in RMI