• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling Large Files

 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!