🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: ibm.software.vajava.language
Article #3

Re: How to read a binary file into an byte array?

#3
From: Jon A. Cruz
Date: Fri, 28 Jan 2000 00:00
28 lines
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.
Technical Details
Message-ID: <3891CE29.676FFD3@geocities.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <949060661946@munich.ixos.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114aa0,7805c4e1f27894f5
X-Google-Attributes: gid114aa0,public
X-Google-Thread: 1089d0,7805c4e1f27894f5
X-Google-Attributes: gid1089d0,public
X-Google-Thread: 104a59,7805c4e1f27894f5
X-Google-Attributes: gid104a59,public
X-Google-Thread: 10a146,7805c4e1f27894f5
X-Google-Attributes: gid10a146,public
X-Google-Thread: fbe9c,7805c4e1f27894f5
X-Google-Attributes: gidfbe9c,public
From: "Jon A. Cruz" <joncruz@geocities.com>
Subject: Re: How to read a binary file into an byte array?
Date: 2000/01/28
Message-ID: <3891CE29.676FFD3@geocities.com>
X-Deja-AN: 578821528
Content-Transfer-Encoding: 7bit
References: <949060661946@munich.ixos.de>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@pacbell.net
X-Trace: nnrp1-w.snfc21.pbi.net 949079288 216.103.55.119 (Fri, 28 Jan 2000 09:08:08 PST)
Organization: SBC Internet Services
MIME-Version: 1.0
NNTP-Posting-Date: Fri, 28 Jan 2000 09:08:08 PST
Newsgroups: ibm.software.vajava.language,borland.public.jbuilder.java.api,borland.public.jbuilder.java,microsoft.public.java.visualj++.general,comp.lang.java.programmer