Java File Handling (I/O)
The java.io package supports the Java's basic I/O (input/output) system, including the file I/O.
As you may have noticed while reading the preceding chapters, not much use has been made of I/O in the example programs. In face, aside from the print() and println(), none of the I/O methods have been used significantly. The reason is simple, most of the literal applications of Java are not text-based, console programs. Rather, they are either graphically oriented programs, rely on one of the GUI (graphical User Interface) frameworks of Java like AWT, Swing, or JavaFX, for the user interaction, or they are the Web applications. Although text-based, console programs are excellent as teaching instances, as they do not establish an important use for Java in the real world. Also, Java's support for console I/O is limited and somewhat difficult to use, even in simple example programs. Text-based console I/O is just not that useful in the real-world Java programming.
Java provides strong, flexible support for the Input/Output (I/O) as it relates the files and networks. Java's I/O system is cohesive and logical. In fact, once you understand its fundamentals, the rest of the I/O system is easy to master.
Java programs performs the Input/Output using streams. You will learn about streams in separate chapter.
Java Read from Console Input
Console input is attained by reading from System.in. You will learn about reading from console input in separate chapter.
Java Write to Console Output
The write() method is used to to write to the console. You will learn about writing to console in separate chapter.
The PrintWriter Class
The PrintWriter is a character-based class. You will learn about PrintWriter in separate chapter.
Java Read from & Write to Files
There are a number of classes and methods in Java, that allows you to read from and write to the files. You will learn about reading and writing files in separate chapter.
Automatically Close a File
The close() method is used to close a file once it is no longer used/needed. You will learn about automatically closing a file in separate chapter.
Java File Handling Example Programs
Here are the list of some example programs that uses files:
- Read from File in Java
- Read & Display File
- Write to File in Java
- Copy File in Java
- Merge two Files in Java
- List files in Directory
- Delete File in Java
« Previous Tutorial Next Tutorial »
Follow/Like Us on Facebook
Subscribe Us on YouTube