Java File Class
Java File Class
The File class is an abstract representation of file and directory pathname. A pathname can
be either absolute or relative.
The File class have several methods for working with directories and files such as creating
new directories or files, deleting and renaming directories or files, listing the contents of a
directory etc.
Fields
Constructors
Constructor Description
File(File parent, String child) It creates a new File instance from a parent abstract pathname and a
string.
File(String pathname) It creates a new File instance by converting the given pathname strin
pathname.
File(String parent, String It creates a new File instance from a parent pathname string and a c
child) string.
File(URI uri) It creates a new File instance by converting the given file: URI into a
pathname.
Useful Methods
static File createTempFile(String prefix, It creates an empty file in the default temporary-
String suffix) the given prefix and suffix to generate its name.
boolean canWrite() It tests whether the application can modify the fil
abstract pathname.String[]
boolean canRead() It tests whether the application can read the file d
abstract pathname.
String[] list(FilenameFilter filter) It returns an array of strings naming the files and
directory denoted by this abstract pathname that
filter.
Output:
Output:
testFile1.txt
/home/Work/Project/File/testFile1.txt
true
/home/Work/Project/File/testFile1.txt Exists? true
Output:
"info.properties"
"info.properties".rtf
.DS_Store
.localized
Alok news
apache-tomcat-9.0.0.M19
apache-tomcat-9.0.0.M19.tar
bestreturn_org.rtf
BIODATA.pages
BIODATA.pdf
BIODATA.png
struts2jars.zip
workspace
Output: