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
- String getName();
- String getParent();
- String getPath();
- String getAbsolutepath();
- Boolean canRead();
- Boolean canWrite();
- Boolean delete();
- Boolean equals();
- Boolean isFile();
- Boolean lastModified();
- Boolean Length();
- 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());
}