🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How can I read in file into a byte array?

#8460
From: Horst Fieseler
Date: Fri, 23 Mar 2001 07:07
30 lines
1673 bytes
"Ben Matterson (Borland)" <bmatterson@borland.com> schrieb im Newsbeitrag
news:3AB7BC0C.60473976@borland.com...
> 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?
like this:

   File fp=new File(fname);
   int flen=(int)fp.length();
   buffer=new byte[flen];
    try{
      BufferedInputStream din=new BufferedInputStream (new
FileInputStream(fp));
     din.read(buffer,0,flen);
      din.close();
    }
    catch(IOException e){
      System.out.println("e);
    }

Horst
Technical Details
Message-ID: <3abaf5a7_2@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!209.50.235.254!europa.netcrusader.net!192.148.253.68!netnews.com!xfer02.netnews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!217.3.21.134
References: <3AB7BC0C.60473976@borland.com>

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 04:07:36 PST
From: "Horst Fieseler" <fieseler@lsgmbh.de>
Newsgroups: borland.public.jbuilder.java.language
References: <3AB7BC0C.60473976@borland.com>
Subject: Re: How can I read in file into a byte array?
Date: Fri, 23 Mar 2001 08:07:11 +0100
Lines: 32
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 217.3.21.134
Message-ID: <3abaf5a7_2@dnews>
X-Trace: 22 Mar 2001 23:05:11 -0800, 217.3.21.134
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!209.50.235.254!europa.netcrusader.net!192.148.253.68!netnews.com!xfer02.netnews.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!217.3.21.134