aspose file tools*
The moose likes Beginning Java and the fly likes What's the difference between read and readFully??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's the difference between read and readFully???

HaoZhe Xu
Ranch Hand

Joined: Nov 03, 2003
Posts: 222
in DataInputStream there're read(byte []) and readFully(byte []), from their names, readFully seems like it read all bytes, so does it mean read can just read partially?


[url]Olnex.net[/url]
[SCJP 1.2, SCJD, SCWCD]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30352
    
150

HaoZhe,
From the API:
read(byte[]) - Reads some number of bytes from the contained input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer.

readFully(byte[]) - Reads some bytes from an input stream and stores them into the buffer array b. The number of bytes read is equal to the length of b.

So readFully() guarantees you the array will be filled up or an exception will be thrown. read() can get away with reading one byte and returning to the caller.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
wood burning stoves
 
subject: What's the difference between read and readFully???