Reading and writing files are fundamental tasks in software development. The Java Development Kit (JDK) offers a comprehensive set of APIs that simplify working with files, directories, and various Input/Output operations, making it easier for programmers to handle these tasks efficiently. The tutorials below will guide you through Java’s File Input/Output operations step-by-step, helping you master these essential skills with ease:
Learn to read user-entered input from keyboard in command line (console) with InputStreamReader, Console and Scanner classes:
The following articles show you how to read and write binary files with InputStream and OutputStream; and how to read and write text files with FileReader and FileWriter classes:
Find the Java code examples to list files and directories (including nested files and directories) in the following posts. You will also learn how to get hard disk's used and free space, and calculate the number of files and directories in any directory.
Learn how to perform common operations on files and directories, such as copy, move, rename, and delete - using both legacy File IO APIs and New IO APIs.
The following articles help you get in-depth understanding about different implementations of InputStream and OutputStream so you'll understand exactly when a FileReader, DataInputStream or ObjectInputStream can be used.
Read the following articles to understand the concepts and usage of serialization in Java IO. I'll also explain externalization which is an advanced form of serialization.
Using the Java IO APIs, programmers can easily write programs that work with compressed files in ZIP format. You can find in the following articles various code examples for reading (extracting) and writing (compressing) ZIP files:
Learn how to format string in the standard output (console), read/write configuration file, execute operating system's commands and watch file change events: