Article View: borland.public.jbuilder.java.language
Article #17971Re: URGENT: Getting File Size
From: Richard Wilkman
Date: Wed, 09 Sep 1998 00:00
Date: Wed, 09 Sep 1998 00:00
68 lines
2587 bytes
2587 bytes
Jason:
available() will return how many bytes you can read without blocking.
This will always vary. What you need to do is something like:
Make a new File object from a string that points to the file (it has
to be on the server).
Use File.length() to get the length of the file.
Make a FileInputStream from the File (you may need to cast this to
InputStream to make the Applet happy).
Create a counter var to count bytes read.
while(bytes_read != file_length){
bytes_read += xxx.read(...); // xxx is the InputStream
...
}
By using the counter var you won't stop reading until you've read the
entire file and don't get stuck on shifting values for available().
-Rich
Jason Terando wrote:
>
> I have an applet polling a file, with the intention of getting new data
> when the file grows. I have been unable to get a consistent file size
> using the Java Plug-In, Netscape 4.05 (1.1 update) or IE 4.01. -- so I
> have a feeling I am not doing something right with the language. Here's
> what I'm doing:
>
> BufferedInputStream inpuytStream;
> long bytesAvailable;
>
> try {
> inputStream = new BufferedInputStream( new
> URL(Source).openStream()); // Source is a string specifiying where my
> file is
> bytesAvailable = inputStream.available();
> }
> catch (Exception e)
> {
> return;
> }
>
> My file is 6993, available() returns anywhere between 4597 and over 9000
> bytes.
>
> HOW DO I GET A FILE'S SIZE?
>
> Thanks!
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rich Wilkman
Senior Quality Assurance Engineer
Borland JBuilder Team
If you see something that looks like an opinion up there,
it's mine and mine alone.
Mail sent to me from the newsgroups won't bounce but will
be ignored. If I have time, I'll respond, but you have
a better chance if you confine your posts to the newsgroups
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID:
<35F71F70.A98005B0@inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35F6ECF5.B923ADE3@eatme.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,457e428e79cd68b2 X-Google-Attributes: gidf74b3,public From: Richard Wilkman <rwilkman@inprise.com> Subject: Re: URGENT: Getting File Size Date: 1998/09/09 Message-ID: <35F71F70.A98005B0@inprise.com> X-Deja-AN: 389579674 Content-Transfer-Encoding: 7bit References: <35F6ECF5.B923ADE3@eatme.com> Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language