🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8424

How can I read in file into a byte array?

#8424
From: Ben Matterson (Borland)
Date: Tue, 20 Mar 2001 20:22
20 lines
1589 bytes
Hello,

Maybe this is a dead easy question and I am just dumb.

I need to read a file of indeterminate length into an array of bytes. 
What I am having trouble with:

How can I know how big to create the array of bytes if I don't know
how big the file is?

How can I read the whole file into the byte array?
fileInputStream.read() reads one byte at a time, so it s seems like a
while loop would do it. But if I am use "FileInputStream.read() != -1"
as the test condition, where do the bytes that are read go? I don't
get how I can test for end of file (-1) *and* put the returned bytes
into the array.

What am I missing? Can someone give me steer in the right direction?

Ben
Technical Details
Message-ID: <3AB7BC0C.60473976@borland.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!sunqbc.risq.qc.ca!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!10.143.12.142

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,2ea00c6aa2f0fa5a
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-23 03:56:02 PST
Message-ID: <3AB7BC0C.60473976@borland.com>
Date: Tue, 20 Mar 2001 12:22:36 -0800
From: "Ben Matterson (Borland)" <bmatterson@borland.com>
Organization: Borland Software Corp
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language
Subject: How can I read in file into a byte array?
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 10.143.12.142
X-Trace: 20 Mar 2001 12:22:34 -0800, 10.143.12.142
Lines: 20
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!sunqbc.risq.qc.ca!nntp1.njy.teleglobe.net!teleglobe.net!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews!10.143.12.142