This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Why this code works differently compiled and interpreted ???
- From: Tom Tromey <tromey at redhat dot com>
- To: "Pedro Izecksohn" <izecksohn at yahoo dot com>
- Cc: <java at gcc dot gnu dot org>
- Date: 16 Apr 2003 22:22:04 -0600
- Subject: Re: Why this code works differently compiled and interpreted ???
- References: <000001c30485$4ca5c680$39aafea9@duron>
- Reply-to: tromey at redhat dot com
>>>>> "Pedro" == Pedro Izecksohn <izecksohn at yahoo dot com> writes:
Pedro> Is something wrong inside this source?
Some indentation would have made this a lot easier to read.
Pedro> really_read = FR.read(content);
You aren't guaranteed to fill the buffer here.
It might work in some cases, but in others it might not.
(The contract for Reader.read doesn't specify that the buffer will be
filled, even if enough data is available.)
In this particular case, it doesn't.
Note that your code has a subtle bug anyway. File.length returns the
length of the file in bytes. However, a Reader converts bytes to
characters -- not necessarily a 1-1 mapping.
So if, for instance, your current encoding is UTF-8 and you read a
file full of multi-byte characters, you could read far fewer
characters than there are bytes.
If you want to read fully, either use RandomAccessFile.readFully, or
write your own function that loops until EOF.
Tom