[Go to site: main page, start]

0% found this document useful (0 votes)
4 views2 pages

Java File Class Methods Overview

The Java File class from java.io provides methods to create, delete, and obtain information about files and directories, but does not handle file content. Key methods include createNewFile(), delete(), exists(), and various permission checks. Each method returns a specific type, such as boolean for existence and permission checks, or String for file and directory names.

Uploaded by

G. Netpryse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Java File Class Methods Overview

The Java File class from java.io provides methods to create, delete, and obtain information about files and directories, but does not handle file content. Key methods include createNewFile(), delete(), exists(), and various permission checks. Each method returns a specific type, such as boolean for existence and permission checks, or String for file and directory names.

Uploaded by

G. Netpryse
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like