File package provides a class known as the File class that provide support for creating files. It deals directly with files and the file system. That is, the File class does not specify how information is retrieved from or stored in files; it describes the properties of a file itself. A File Object is used to obtain or manipulate the information associated with a disk file. It will give the permission, directory path and so on.

File defines many methods that obtain the standard properties of a File object. For example, getName( ) returns the name of the file, getPath( ) returns the path of the file, getParent( ) returns the name of the parent directory, exists( ) returns true if the file exists, false if it does not, and isFile( ) returns true if called on a file and false if called on a directory.



Program Source


public class Javaapp {

    public static void main(String[] args) {
        File f1 = new File("F:\\java8");
        System.out.println("Folder Name        : "+f1.getName());
        System.out.println("Full Path          : "+f1.getPath());
        System.out.println("Parent of          : "+f1.getParent());
        System.out.println("java8 Folder is    : "+f1.exists());
        System.out.println("java8 is a File    : "+f1.isFile());

Leave a Comment