Java File Class Methods
File Class Methods
The File class (from [Link]) is used to work with file and directory paths.
It lets you create, delete, and get information about files and folders - but it
does not read or write the contents.
Method Description Return
Type
createNewFile Creates a new, empty file if it does not boolean
() already exist
delete() Deletes the file or directory boolean
exists() Tests whether the file or directory exists boolean
canRead() Tests whether the application can read boolean
the file
canWrite() Tests whether the application can write to boolean
the file
isFile() Returns true if the path represents a file boolean
isDirectory() Returns true if the path represents a boolean
directory
length() Returns the size of the file in bytes long
getName() Returns the name of the file or directory String
getAbsolutePa Returns the absolute pathname string String
th()
getPath() Returns the pathname string String
getParent() Returns the pathname string of the parent String
directory
list() Returns an array of names of files and String[]
directories in a directory
listFiles() Returns an array of File objects in a File[]
directory
mkdir() Creates a directory boolean
mkdirs() Creates a directory and any missing boolean
parent directories
renameTo() Renames the file or directory boolean
setReadOnly() Marks the file as read-only boolean
setWritable() Sets the writable permission boolean
setReadable() Sets the readable permission boolean
setExecutable Sets the executable permission boolean
()
canExecute() Tests whether the application can execute boolean
the file
Related Pages