Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

File handling

FILE HANDLING:

File handling in java comes under input output (IO) operations. Classes used in file handling in Java are present Java IO package (java.io).

Some of the file handling operations are:
  • Create file
  • Delete file
  • Read file
  • Write file
  • Changes file permissions, etc.

Program for create operation in file handling:

package com.journaldev.files;
import java.io.File;
import java.io.IOException;
public class FileHandling {
      public static void main(String[] args) throws IOException {
               File file = new File(“profjayesh.txt”);
                         boolean createNewFile = file.createNewFile();
                         System.out.println(“File Created = “+createNewFile);
               }
      }
OUTPUT:
File Created = true

Program for delete operation in file handling:

package com.journaldev.files;
import java.io.File;
public class FileHandling {
      public static void main(String[] args) {
               File file = new File(“profjayesh.txt”);
               boolean delete = file.delete();
               System.out.println(“File deleted = “ + delete);
      }
}
OUTPUT:

File deleted = true