RFR [8020669] java.nio.file.Files.readAllBytes() does not read any data when Files.size() is 0
Christos Zoulas
christos at zoulas.com
Tue Jul 23 15:31:23 UTC 2013
On Jul 22, 11:58am, martinrb at google.com (Martin Buchholz) wrote:
-- Subject: Re: RFR [8020669] java.nio.file.Files.readAllBytes() does not rea
| It's the OS/filesystem implementer deciding to return a bogus number.
|
| More accurate would be to count by reading all the bytes, but that is
| impractical and/or impossible (e.g. don't try reading "all the bytes" from
| /dev/null)
|
| A middle ground would be to mistrust specifically file sizes of zero,
| testing via
| int c = read()
| but then what? Check for /proc bug on Linux?
The only sure way to read all the data from a file in Unix is to attempt
to read(2) until it returns 0 (or -1 on error). If you think you can trust
the size stat(2) returns what does it return for /dev/zero? :-)
christos
More information about the core-libs-dev
mailing list