Category Archives for java.io

Java InputStream

InputStream is an abstract class based on which all other InputStreams are derived.

InputStreams are used to read bytes of data from a data source.

It differs from a Reader, in that , a Reader deals with characters, while Stream is for bytes.

Major functions

This is abstract function that will be implemented by child classes. Used for reading next byte from the data source.
returns the byte that is read. If there is nothing to read, returns -1

This function reads array of bytes up to the size of the array. If there is no enough data up to the size of the array, reads maximum from the data source.
returns the number of bytes read. If there is nothing to read, returns -1

Very similar to the function read(byte[] bArray). However, here you can specify the offset from which it should be start reading.
return value is same as read(byte[] bArray).

 

Java File Operations with Code Samples

java file operationsJava gives extensive set of libraries to work on files. In general when it is to do with reading and writing, Java gives you input stream and output stream. It is the same for files too.

When dealing with Java File Operations, you have bit more things possible to do. Here are the main operation done in a file and how to do it. Continue reading