Ads

Thursday, 11 January 2018

File Class in Java


File Class


The Java File Class is used for the creation of files and direction, get file path information, searching file, and deletion etc.

The File class is an abstract representation of file and directory pathname. A pathname can be either absolute or relative.

Constructors Of File Class



  • file(String path);
  • file(String directory, String filename);
  • file(file obj, String filename);

Method Of File Class




  1. String getName();
  2. String getParent();
  3. String getPath();
  4. String getAbsolutepath();
  5. Boolean canRead();
  6. Boolean canWrite();
  7. Boolean delete();
  8. Boolean equals();
  9. Boolean isFile();
  10. Boolean lastModified();
  11. Boolean Length();
  12. String list();


Example Of  File Class



import java.io.*;
class Filedemo
{
      public static void main(String args[])
       {
               File f1=new File("E:/java/");
               File f2=new File("E:/java/","T.txt");
               File f3=new File(f1,"t.java/");
                 
                System.out.println("Filename of f1"+f1.getName());
                System.out.println("Filename of f2"+f2.getName());
                System.out.println("Filepath of f1"+f1.getAbsolutePath());
                System.out.println("Is File"+f1.isFile());
       }

Post a Comment

Click Here