Read/Write File In Java (java.io)

In Java, files can be processed by either streams or buffers.

java.io Library – helps in file processing by streams, where this is a classic one.
java.nio Library – helps in file processing by buffers, using nio(non blocking IO) is the latest one supported from Java 1.5

Streams are used to process files in Java.io package.
Byte Streams – FileInputStream/FileOutputStream, BufferedInputStream etc.,
Character Streams – FileReader/FileWriter etc.,

The following example provides an idea of how files can be read/write using byte streams.

Read File using FileInputStream in Java

Result:

Write content into File using FileOutpuStream

Result: 

Leave a Reply

Your email address will not be published. Required fields are marked *