Java File class represents the path of directories and files. It provides the methods for renaming, deleting, and obtaining the properties of a file or directory. The File class is the wrapper class for the file name and its directory path.

Java File Class

The File class is Java’s representation of the file or directory pathname. Because file and directory names have different formats on different platforms, a simple string is not adequate to name them. A File class contains several methods for working with the pathname, deleting and renaming files, creating new directories, listing the contents of an index, and determining several common attributes of files and directories.

  1. It is an abstract representation of file and directory pathnames.
  2. The pathname, whether abstract or in the string form can be either absolute or relative. The parent of the abstract pathname may be obtained by invoking a getParent() method of this class.
  3. First of all, we should create a File class object by passing a filename or directory name to it. The file system may implement restrictions to certain operations on the actual file-system object, such as the reading, writing, and executing. These restrictions are collectively known as access permissions.
  4. Instances of a File class are immutable; that is, once created, the abstract pathname represented by the File object will never change.

The pathname can be absolute or relative.

#java #java.io #java.io file class

Java File Class Tutorial | Java.io File Class in Java Example
2.70 GEEK