• 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

Handling Large Files

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a File Transfer program for my class. Right now I'm converting the file into a byte array.
However, when I try to convert a file that is of 90 meg size, I get a error. But I don't get it when I do it to a 45 meg file.
So, I was wondering, could I split a single file variable into multiple file variables that points to a different section of the same file?
Thanks in advance.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I was wondering, could I split a single file variable into multiple file variables that points to a different section of the same file?
I don't think so. What do you mean by "file variable"? A File object? A RandomAccessFile? A FileInputStream? Something else? These all refer to the whole file, not just part of it.
I think the key is that you're trying to put all the bytes into one big array at once. You don't have to do this. You can use a smaller byte[] array, and keep re-using it. Read some bytes to fill the array, write those bytes to the new file, then read some new bytes into the array (overwriting the ones previously stored there), and write those to the new file. Repeat until done.
If you're using JDK 1.4 there's a much faster way to do this using FileChannels. But I'm guessing for a class they probably want you to figure out how to do this with streams first.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic