Sep 28, 2014

Internal mechanism of File Handling in java

Internals of File Handling in Java

File Handling is a very important topic in java. We can read, write, update files through file handling. It gives us authority to modify files through this mechanism. We will read here internal mechanism of file handling. How files are being read, How Input/Output operation are being performed on file. In order to read about all this we need to understand STREAM. We will discuss here-

  *What is Stream?

  *What is INPUT?

  *What is OUTPUT?

  *What is Input Stream?

  *What is Output Stream?

  *What is Byte Stream?

  *Why do we need Byte Stream?

  *What is Character Stream?

  *Why do we need Character Stream?

  *How many ways to take Input from keyboard?

We will get all answer here while reading all posts. First I would like to tell you concept of File Handling.

File Handling-

We can  read or write something from/to file with file handling mechanism. Our basic purpose is to retrieve or update file through this mechanism. For this we need to connect particular file with java environment. We create a connection between java environment and file and a Stream of data passes from this connection. Stream can be said as a sequence of data.

File handling functions are:

·         We can create  file for reading or writing purpose

·         Read data from file 

·         Writing data in file

·         Appending data to file

·         Assigning name to file
·         Renaming file
·         Positioning to particular byte in the file
·         Checking end of line in the file
·         Can find size of the file
·         We can delete the file
·         Returning result of last file input/output operation
·         Closing file.

Below is a program to understand Internal Mechanism of File Handling.


public class ZCopyFile {
   public static void main(String args[]) throws IOException
      FileInputStream in = null;
      FileOutputStream out = null;

      try {
         in = new FileInputStream("input.txt");
         out = new FileOutputStream("output.txt");
         int uc;
         while ((uc = != -1) {
     finally {
         if (in != null) {
         if (out != null) {

Please Click here to read next about file handling in java.