JavaI/O Streams
I/O Streams (Input/Output Streams)
You've already seen how to create, read, and write simple text files.
In Java, there is an important difference between working with theFile class and working withI/O Streams (Input/Output Stream):
- The
Fileclass (fromjava.io) is used toget information about files and directories:- Does the file exist?
- What is its name or size?
- Create or delete files and folders
But: the
Fileclass doesnot read or write the contents of the file.
So far, we have usedFileWriter for writing text andScanner for reading text. These are easy to use, but they are mainly designed for simpletext files.
I/O Streams are more flexible, because they work with textand binary data (like images, audio, PDFs).
Types of Streams
- Byte Streams
Work with raw binary data (like images, audio, and PDF files).
Examples:FileInputStream,FileOutputStream. - Character Streams
Work with text (characters and strings). These streams automatically handle character encoding.
Examples:FileReader,FileWriter,BufferedReader,BufferedWriter.
Tip: Use character streams when working with text, and byte streams when working with binary data.

