Link to home
Create AccountLog in
Avatar of AlphaLolz
AlphaLolzFlag for United States of America

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\filename.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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The class at the link here has also a fileToByteArray method:

http://technojeeves.com/joomla/index.php/free/93-file-to-string-in-java
Avatar of AlphaLolz

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.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
:)
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?
> This looks pretty efficient.  Fewest lines I've seen.

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
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).
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
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.