Quite simple: in the second method he creates an array of zero length
because he sets llen to f.length(). Well as we already discussed, the
file will appear to have zero length, which means llen == 0 and
when he initializes b, he uses new byte[len]...a zero-length array. Therefore
it makes perfect sense that nothing would be read into the array, since
readFully() will only read as many bytes into the array as can fit.
The disparity between the two methods is that method 1 does not use the length
of the file at all. It simply reads lines until there's no more lines to
read (in other words, the last line read is null). That's basically what
my example does, only I didn't much with BufferedReader, I simply did it
char by char (less efficient perhaps, but its a proof of concept). The
second method tries to "predict" how many bytes there are, by checking the
file size, which we know will be zero.
And lo, the chronicles report that Dimitris Vyzovitis spake thusly unto the masses:
>
> Aaron Gaudio wrote:
>
> > Where did you get this idea? FileReader and FileInputStream both work
> > the same.
>
> Try this (Sean Kellner's code -> [EMAIL PROTECTED])
>
> [Code snipped -Ed.]
>
>
> I also used to think that the Reader and the Stream work the same way, but it seems
>they don't.
> Any clues (please don't quote "Java in a Nutshell", I also have the book) ?
Why not? It may at times be vague or lacking, but what information it does
provide is unerringly correct.
--
¤--------------------------------------------------------------------¤
| Aaron Gaudio mailto:[EMAIL PROTECTED] |
| http://www.rit.edu/~adg1653/ |
¤--------------------------------------------------------------------¤
| "The fool finds ignorance all around him. |
| The wise man finds ignorance within." |
¤--------------------------------------------------------------------¤
Use of any of my email addresses is subject to the terms found at
http://www.rit.edu/~adg1653/email.shtml. By using any of my addresses, you
agree to be bound by the terms therein.