The source code from this guide is bug-free and used JDK 8 to compile and execute the source code.
Java I/O Basics
- Overview of Java I/O - In this article, we will learn the basics of Java I/O, an overview of different I/O Streams from the java.io package, overview of the classes in the Java IO (java.io) package and Java IO Purposes and Features.
- Java I/O Byte Streams - In this post, we will learn how to develop programs which use byte streams to perform input and output of 8-bit bytes.
- Java I/O Character Streams - In this post, we will discuss the character stream I/O classes with examples.
- Java I/O Buffered Streams - In this article, we will discuss four buffered stream classes used to wrap unbuffered streams with examples.
- Java I/O Object Streams - We will look into the object stream classes are ObjectInputStream and ObjectOutputStream. These classes implement ObjectInput and ObjectOutput, which are subinterfaces of DataInput and DataOutput.
- Java I/O Data Streams - In this article, we will discuss Data Stream classes DataInputStream and DataOutputStream with examples.
Java I/O Classes
- FileOutputStream Class in Java - In this article, we will discuss FileOutputStream Class constructors, Methods/APIs with examples.
- FileInputStream class in Java - In this article, we will discuss FileInputStream Class constructors, Methods/APIs with examples.
- ByteArrayOutputStream Class in Java - In this article, we will discuss ByteArrayOutputStream Class constructors, Methods/APIs with examples.
- ByteArrayInputStream Class in Java - In this article, we will discuss ByteArrayInputStream Class constructors, Methods/APIs with examples.
- BufferedWriter Class in Java - In this article, we will discuss BufferedWriter Class constructors, Methods/APIs with examples.
- BufferedReader Class in Java - In this article, we will discuss BufferedReader Class constructors, Methods/APIs with examples.
- BufferedOutputStream Class in Java - In this article, we will discuss BufferedOutputStream Class constructors, Methods/APIs with examples.
- BufferedInputStream Class in Java - In this article, we will discuss BufferedInputStream Class constructors, Methods/APIs with examples.
- FileWriter Class in Java - In this article, we will discuss FileWriter Class constructors, Methods/APIs with examples.
- FileReader Class in Java - In this article, we will discuss FileReader Class constructors, Methods/APIs with examples.
- DataOutStream Class in Java - In this article, we will discuss DataOutStream Class constructors, Methods/APIs with examples.
- DataInputStream Class in Java - In this article, we will discuss DataInputStream Class constructors, Methods/APIs with examples.
- ObjectOutputStream Class in Java - In this article, we will discuss ObjectOutputStream Class constructors, Methods/APIs with examples.
- ObjectInputStream Class in Java - In this article, we will discuss ObjectInputStream Class constructors, Methods/APIs with examples.
File Handling Examples
- How to create a new file in java - In this article, we will learn how to create a file with a Java program.
- How to Write File in Java - In this example, we will use a BufferedWriter class to write the file. There are other Stream Output classes to write the file but in this example, we will focus on frequently used BufferedWriter.
- How to delete a file in Java - It is very simple to delete a file from a specific directory. Java File class provides delete() method can be used to delete files or empty directory/folder in java.
- How to Copy File in Java - This example shows how to copy a file using a Java program.
- How to Move a File in Java - This example shows how to move a file using a Java program.
- How to Rename File in Java - In this example, we will renameTo() method to rename a file.
- How to Append to File in Java - This example shows how to append a file using a Java program.
- Read File using BufferReader - In this example, we will use a BufferedReader class to read a file named "sample.txt". BufferedReader class is used to read the text from a character-based input stream. It can be used to read the data line by line by the readLine() method. It makes the performance fast.
- Read File using BufferInputStream - In this example, we will use a BufferedInputStream class to read a file. The BufferedInputStream class is used to read information from the stream. It internally uses a buffer mechanism to make the performance fast.
- Read File using DataInputStream - In this example, we will DataInputStream class to read a file. A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream.
- Get File Size in Bytes KB MB GB TB - In this example, we will write a generic method to get file size in bytes, kilobytes, megabytes, GB, TB.
File Serialization Examples
- How to write an Object to file in Java - In this example, we will use ObjectOutputStream class to write an employee object to file.
- How to Read Object from File - In this example, we will use ObjectInputStream class to read employee object to file.
File Compression Examples
- Compress Files in ZIP format in Java - In this article, we will show you how to compress a single file to zipping and multiple files to zip format. The example from this article uses the try-with-resources Statement to auto-close the resources and compiled and executed on JDK 8 and later.
- Decompress Files from a ZIP file in Java - In this article, we will show you how to unzip it. The example from this article uses the try-with-resources Statement to auto-close the resources and compiled and executed on JDK 8 and later.
Directory Handling Examples
- How to Get the Current Working Directory in Java - The current working directory means the root folder of your current Java project, it can be retrieved by using the following system property function.
- Create a directory - In this example, we will create a Java program to create a directory on a file system.
- Delete directory - In this example, we will delete a directory using a Java program.
- Copy directory - We will write a Java program to copy directory.
- Traverse /List a directory structure - We will list out a number of files under directory using Java program.
- Check if a directory is empty - Java program to check if a directory is empty or not.
File Utilities (Development)
- Java File Utility Class - In this article, we will show you the list commonly used file utility methods. This File Utility class contains more than 20 file utility methods and all are commonly used methods. Hope this FileUtils.java class will help.
- Java Zip Utility Class - In this article, we will discuss a few commonly used Java Zip utility methods. We can also show you the sample JUnit test cases for zip utility methods. ZipUtils contains below generic methods.
- Top File Utility Methods - In this article, we will discuss 20 useful commonly used file utility methods. You can use these file utility methods in your day to day project work. I found these utility methods are useful and I thought I should share with you all.
Java I/O Reference
Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours
Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course