bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java File Class Methods

Flash cards

Review the key moves

1/3
Core idea

What is the main idea behind Java File Class Methods?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

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