AlphaLolz
asked on
Reading remote file into byte array
All,
We have a need to read a file into a byte array. These files are large (can be up to 100 MB) so we need something very efficient/quick. I've seen some examples, but I'm looking for what the experts would consider the fastest way to do this. A code snippet.
As said above we want to read these from a remote file share (this is all running on Windows), so we need to read from a \\fileserver\folder\filena me.txt type of syntax.
Will give all 500 points to anyone providing a short working sample. We've seen some out there, but don't know if: 1, they work with a remote file; 2, if they're the most efficient approach.
Thanks
We have a need to read a file into a byte array. These files are large (can be up to 100 MB) so we need something very efficient/quick. I've seen some examples, but I'm looking for what the experts would consider the fastest way to do this. A code snippet.
As said above we want to read these from a remote file share (this is all running on Windows), so we need to read from a \\fileserver\folder\filena
Will give all 500 points to anyone providing a short working sample. We've seen some out there, but don't know if: 1, they work with a remote file; 2, if they're the most efficient approach.
Thanks
ASKER
This looks pretty efficient. Fewest lines I've seen.
How would I use this with a remote Windows file though? Can you specify the syntax for that? I needed that too.
How would I use this with a remote Windows file though? Can you specify the syntax for that? I needed that too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)
ASKER
Yes these files will be large. Some will be in the 100-150 MB range.
Would you recommend nio then? Even for across the network?
Would you recommend nio then? Even for across the network?
this will be a lot faster
http://helpdesk.objects.com.au/java/how-do-i-read-the-contents-of-a-file-into-a-byte-array
http://helpdesk.objects.com.au/java/how-do-i-read-the-contents-of-a-file-into-a-byte-array
> This looks pretty efficient. Fewest lines I've seen.
its actually about the least efficient
its actually about the least efficient
>>Would you recommend nio then? Even for across the network?
Yes - it's worth trying. You can of course benchmark both
Yes - it's worth trying. You can of course benchmark both
ASKER
By what measure is it more efficient?
I'm not looking for fewest lines (although I said that). I'm looking for the fastest and the least resources consumed (particularly memory).
I'm not looking for fewest lines (although I said that). I'm looking for the fastest and the least resources consumed (particularly memory).
use the link I posted, converting an entire file into a string as suggested earlier will be slow and require additional memory
if you want to read the string data then instead use something like this
http://helpdesk.objects.com.au/java/how-do-i-read-a-text-file-line-by-line
if you want to read the string data then instead use something like this
http://helpdesk.objects.com.au/java/how-do-i-read-a-text-file-line-by-line
ASKER
thanks,
We're not going to go all the way to creating a string though (from the original posting). We're going to stop with the byte array since that's what we need.
We're not going to go all the way to creating a string though (from the original posting). We're going to stop with the byte array since that's what we need.
http://technojeeves.com/joomla/index.php/free/93-file-to-string-in-java