bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java File Class Methods

File Class Methods

The File class (from java.io ) 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.

MethodDescriptionReturn Type
createNewFile()Creates a new, empty file if it does not already existboolean
delete()Deletes the file or directoryboolean
exists()Tests whether the file or directory existsboolean
canRead()Tests whether the application can read the fileboolean
canWrite()Tests whether the application can write to the fileboolean
isFile()Returns true if the path represents a fileboolean
isDirectory()Returns true if the path represents a directoryboolean
length()Returns the size of the file in byteslong
getName()Returns the name of the file or directoryString
getAbsolutePath()Returns the absolute pathname stringString
getPath()Returns the pathname stringString
getParent()Returns the pathname string of the parent directoryString
list()Returns an array of names of files and directories in a directoryString[]
listFiles()Returns an array of File objects in a directoryFile[]
mkdir()Creates a directoryboolean
mkdirs()Creates a directory and any missing parent directoriesboolean
renameTo()Renames the file or directoryboolean
setReadOnly()Marks the file as read-onlyboolean
setWritable()Sets the writable permissionboolean
setReadable()Sets the readable permissionboolean
setExecutable()Sets the executable permissionboolean
canExecute()Tests whether the application can execute the fileboolean

Previous

Java Scanner useRadix() Method

Next

Java FileInputStream Methods