• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download large files in RMI

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getting this error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

How do i get the temp file to my client side.?
 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

reply
    Bookmark Topic Watch Topic
  • New Topic