# Files and I/O Operations In Java: -

&#x20;The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, object, localized characters, etc.)

#### &#x20;Stream

&#x20;A stream can be defined as a sequence of data. There are two kinds of Streams −

* &#x20;InputStream − The InputStream is used to read data from a source.
* &#x20; OutputStream − The OutputStream is used for writing data to a destination.&#x20;

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTkhRRinkdSDMELKzTB%2Fimage.png?alt=media\&token=99f6b416-7937-4602-acc6-748a62832ca4)

&#x20;Java provides strong but flexible support for I/O related to files and networks but this tutorial covers very basic functionality related to streams and I/O&#x20;

**Reading and Writing Files**

&#x20;As described earlier, a stream can be defined as a sequence of data. The InputStream is used to read data from a source and the OutputStream is used for writing data to a destination.

&#x20;Here is a hierarchy of classes to deal with Input and Output streams.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTkhdwAM_2XnZKdjhBk%2Fimage.png?alt=media\&token=f528bbe1-841c-4222-af86-bf31cb3b4090)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTkhm-MquZtPjBN2d5T%2Fimage.png?alt=media\&token=c086fb39-d938-43e6-90b8-a2311c4a3204)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTkhq0-k6vUBp2HvchI%2Fimage.png?alt=media\&token=897cbc21-3e8c-4492-b3d6-abb51cdfd7e5)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTkhxI6WafKUd64L8_-%2Fimage.png?alt=media\&token=1258c871-63e6-4a6c-a3f6-439b2a49d40f)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTkh-r3gzXKNwxe3bZW%2F-LTki1oBNM1jhR516XYv%2Fimage.png?alt=media\&token=2aea0bb4-6f08-4686-9974-4961e4e60b5d)

