This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32481
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
Have you checked out Aspose?
 
subject: What's the difference between read and readFully???
 
It's not a secret anymore!