Java ObjectInputStream read() MethodThe read() method of java.io.ObjectInputStream is used to read a byte of data. Some data must be present to read in inputstream. It returns an integer value indicating the number of bytes read. It returns -1 if the end of the stream is reached without reading a single byte. SyntaxParameterNo parameter is passed. ReturnsReturns an integer value. ThrowsIOException Example 1Output: End of the stream is reached Hello javaTpoint Example 2Output: Hello End of the stream is reached javaTpoint available byte to read 0 Java ObjectInputStream read() MethodThe read() method of ObjectInputStream class is used to read the data and store into an array of bytes. There must be some data in the stream to use this method. This method accepts 3 parameters. The buf is byte array into which data is stored. The Off is starting offset to start reading, and len is the length of bytes to read. SyntaxParameterbuf - the buffer into which the data is read off - the start offset in the destination array buf len - the maximum number of bytes read ReturnsIt returns an integer indicating the number of bytes read. It returns -1 if there is no data present in the stream. ThrowsNullPointerException , IndexOutOfBoundsException ,IOException . Example 1Output: Hello javaTpoint No of bytes read : 6 Example 2Output: Hello No of bytes read : 6 javaTpoint
Next TopicJava ObjectInputStream
|