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 stream concept, this stream in java.io package supports all classes that need to be required to perform the input and output operations. A stream that used in the I/O is a sequence of data and classified in 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
10. D:\\IO\\: This path indicates that the permission is associated with all sub files and directories respectively.
11. D:\\IO\\*: This path indicates that the permission is associated with all files and directories within this specified directory except subdirectories.
12. Console: This class is internally attached to the system console, used to get the input from the console 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).
13. Scanner: This class in inbuilt, found in java.util package. This class is used to read the data from the keyboard, allow to get the input from the user 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.
14. 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.
15. 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.
16. 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 third, and so on.
17. 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
18. 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.
19. 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.
20. StringReader: This class is a character stream that takes an input string and converts it into a character stream using reader class.
21. StringWriter: This class is a character stream that takes output string which can be used to construct a string. It inherits the writer class.
22. FileReader: FileReader is a character oriented class used to read the data from the specified file and return the data in byte format.
23. FileWriter: FileWriter is a character oriented class used to write the data to a specified file.
24. ObjectStreamClass: This class acts as a serialization description of classes. It stores the name and serialVersionID of the class.
25. ObjectStreamField: In Java, this class is used to initialize the serializable filed of class.
26. ByteArrayInputStream: This class uses an internal buffer to read the byte array from the input stream.
27. ByteArrayOutputStream: This class is used to write the data into a byte array.
Conclusion: In this article, we have seen what are Java I/O Classes to perform input-output operations in Java.
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 –