Thread View: ibm.software.vajava.language
3 messages
3 total messages
Started by Hannes Heckner
Fri, 28 Jan 2000 00:00
How to read a binary file into an byte array?
Author: Hannes Heckner
Date: Fri, 28 Jan 2000 00:00
Date: Fri, 28 Jan 2000 00:00
13 lines
1383 bytes
1383 bytes
Hi, I need some java code to read efficiently a binary file into a byte array. Best would be if the entire file would be read in one step into the array (for best performance) Thanks for any tip Hannes If you know a solution to this problem, please submit it to http://www.the-codebook.com/show_code.asp?ProblemId=1298 +++++++++++ Posted via The-Codebook.Com, The Source for Developers +++++++++++ http://www.The-Codebook.com/ Java, VisualBasic, VisualC++
Re: How to read a binary file into an byte array?
Author: William Brogden
Date: Fri, 28 Jan 2000 00:00
Date: Fri, 28 Jan 2000 00:00
18 lines
1395 bytes
1395 bytes
Hannes Heckner wrote: > > Hi, > > I need some java code to read efficiently a binary file > into a byte array. Best would be if the entire file would > be read in one step into the array (for best performance) > > Thanks for any tip > Hannes > You should be looking at methods in java.io.RandomAccessFile or java.io.FileInputStream WBB
Re: How to read a binary file into an byte array?
Author: Jon A. Cruz
Date: Fri, 28 Jan 2000 00:00
Date: Fri, 28 Jan 2000 00:00
28 lines
2557 bytes
2557 bytes
Hannes Heckner wrote: > Hi, > > I need some java code to read efficiently a binary file > into a byte array. Best would be if the entire file would > be read in one step into the array (for best performance) How do you know this will give you best performance? Have you measured it? Obviously not, since you don't yet have that solution. I'm not necessarily saying that it won't be better, but that programmers making assumptions is a bad thing. As is attributed to Knuth: "Premature optimization is the root of all evil." In studies, it turns out that programmer intuition on what to change in a program to make things work faster is most often wrong. Just to play devil's advocate, what if in reading the entire file at once, you end up blocking and waiting for the relatively slow disk IO to perform, whereas just looping and reading bytes as they become available won't free the low-level internals of the Java VM to do some housekeeping in the meantime and thus give you better overall performance? One main thing will tell you: measuring performance. And of course you have to factor in the different platforms, different versions of VM's available, etc. Sorry, I just like to try to help stop bad habits before they get entrenched. -- "My new computer's got the clocks, it rocks But it was obsolete before I opened the box" - W.A.Y.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads