In this section we will discussed about How files can be handled in Java.
File Handling In Java
In this section we will discussed about How files can be handled in Java.
In this tutorial we will learn the various aspect of file handling in Java.
Most of the software's important feature is how to read data of a file and/or write them to a file. In Java java.io package is available that lets the Java Developer to handle files. java.io package contains the classes which are required in to perform input and output operations in Java.
When we are talking about the input and output operations we will be required to deal with the streams. So, first we will discussed about the Stream.
What is Stream ?
We can say that a stream is a different kinds of sources and destinations such as the disk files, devices, memory arrays. Stream is a sequence of data (simple bytes, primitive data types, localized characters, objects) which flows the information that may be an input source or an output destination for example a console, file, buffer, etc. In Java you will see the various I/O Streams
- Byte Streams : This Stream handles the binary i.e. 8-bit input/output data.
- Character Streams : This Stream handles the character.
- Buffered Streams : This Stream handles the buffered input/output steams.
- Data Streams : This Stream handles the 8-bit input/output primitive data type and String values.
- Object Streams : This Stream handles the input/output of objects.
- Scanning and Formatting : This Stream handles the input/output scanned and formatted text.
- I/O from the Command Line : This Stream handles the Standard Streams and Console.
As we will progress in our discussion, we will be required to deal with the Stream classes and the Reader/Writer classes. So, here we will first discussed the difference between these classes.
Stream Classes | Reader/Writer Classes |
Stream classes are byte oriented | Reader/Writer classes are character oriented |
Doesn't support Unicode characters | Supports Unicode characters |
Perform input/output of 8-bit bytes | Perform input/output of 16-bit Unicode characters |
Since JDK 1.0 | Since JDK 1.1 |