Introduction to Java IO
Java I/O stands for Java Input and Output. In other words, we can say that Java takes input from the user and then performs the appropriate action to generate the output. i.e. Java I/O simply processes the input and generates the output.
To make the I/O operations fast, Java uses the stream concept; this stream in the java.io package supports all classes that need to be required to perform the input and output operations. A stream that is used in the I/O is a sequence of data and is classified into two parts – InputStream and OutputStream, where InputStream is used to read the data from the source, and OutputStream is used to write the data to a destination.
Java I/O Classes
Below is the list of classes that are used to perform the I/O operations:
1. FileInputStream: In Java, FileInputStream class is used to read the data such as audio, video, images, etc., in byte format. i.e. this class simply read the bytes from the source file.
2. FileOutputStream: In Java, FileOutputStream class works opposite of FileInputStream class; it writes the data such as audio, video, image, etc., in a byte and character format. i.e. this class writes the data to file.
3. DataInputStream: This class allows the application to read the primitive data from the input stream in a machine-independent way.
4. DataOutputStream: This class allows an application to write the primitive data to the output stream in a machine-independent way.
5. BufferedReader: This class allows to read the text from a character-based input stream in line-by-line format by inheriting the reader class.
6. BufferedWriter: In java, this method provides buffering to write the instances by inheriting the writer’s class.
7. BufferedInputStream: This class is used to read the data from the input stream. The internal buffer array is initialized automatically once the BufferedInputStream is created. When bytes from the stream are read, the internal buffer is automatically refilled from the source input stream.
8. BufferedOutputStream: This class is used to buffer the output stream. To store the data, this class uses an internal buffer. i.e. this class adds buffer in OutputStream.
9. FilePermission: This class is used to give the appropriate permission to file or directory; these permissions are related to the file path.
File path can be of two types:
- D:\\IO\\: This path indicates that the permission is associated with all sub files and directories respectively.
- D:\\IO\\*: This path indicates that the permission is associated with all files and directories within this specified directory except subdirectories.
10. Console: This class is internally attached to the system console and used to get the console’s input by providing various methods. Console class can read both text and password where the text will be displayed to the user, and the password will not be displayed (can be shown in star format).
11. Scanner: This class in inbuilt, found in java.util package. This class is used to read the data from the keyboard and get the user’s input in primitive data types (int, float, long, double, string, etc.) To get the scanner class to read the input from a user, we need to pass the input stream, i.e. System.in.
12. FilterInputStream: This class implements the InputStream and uses various subclasses such as BufferedInputStream and DataInputStream to provide additional functionality. It simply overrides all InputStream methods.
13. FilterOutputStream: This class works opposite of FilterInputStream. It implements OutputStream and uses various subclasses such as BufferedOutputStream and DataOutputStream to provide additional functionality. It simply overrides all OutputStream methods.
14. SequenceInputStream: As the name suggests, this class read the data in sequential format, i.e. one by one. This class starts reading the data from the first one until the end of the file reached; then it starts reading the second one, then the third, and so on.
15. RandomAccessFile: This class is used to access the random file; this random access file is a large array of bytes. It is commonly used for reading and writing to a random file, read and write operations are performed using a cursor
16. InputStreamReader: This class acts as a bridge that joins the byte stream to the character stream. It first reads byte and then decodes it into character using a specified charset.
17. OutputStreamWriter: This class works opposite of InputStreamReader. It converts the character stream to the byte stream. It first read the character and then decodes it into byte using a specified charset.
18. StringReader: This class is a character stream that takes an input string and converts it into a character stream using the reader class.
19. StringWriter: This class is a character stream that takes an output string which can be used to construct a string. It inherits the writer class.
20. FileReader: FileReader is a character-oriented class used to read the specified file data and return the data in byte format.
21. FileWriter: FileWriter is a character-oriented class used to write the data to a specified file.
22. ObjectStreamClass: This class acts as a serialization description of classes. It stores the name and serial version id of the class.
23. ObjectStreamField: In Java, this class is used to initialize the class’s serializable field.
24. ByteArrayInputStream: This class uses an internal buffer to read the byte array from the input stream.
25. ByteArrayOutputStream: This class is used to write the data into a byte array.
Conclusion – Java IO
In this article, we have seen what are Java I/O Classes to perform input-output operations in Java.
Recommended Articles
This is a guide to Java IO. Here we discuss the introduction to Java IO and its list of classes that are used to perform the I/O operation. You can also go through our other suggested articles to learn more –
41 Online Courses | 29 Hands-on Projects | 305+ Hours | Verifiable Certificate of Completion
4.8
View Course
Related Courses