I'm implementing a file transfer server, and I've run into an issue with sending a file larger than 2 GB over the network. The issue starts when I get the File
I want to work with and try to read its contents into a byte[]
. I have a for loop :
for(long i = 0; i < fileToSend.length(); i += PACKET_SIZE){
fileBytes = getBytesFromFile(fileToSend, i);
where getBytesFromFile()
reads a PACKET_SIZE
amount of bytes from fileToSend
which is then sent to the client in the for loop. getBytesFromFile()
uses i
as an offset; however, the offset variable in FileInputStream.read()
has to be an int
. I'm sure there is a better way to read this file into the array, I just haven't found it yet.
I would prefer to not use NIO yet, although I will switch to using that in the future. Indulge my madness :-)