File

An abstract representation of file and directory pathnames.

Constants from File class

ReturnFieldSummary
static StringpathSeparatorThe system-dependent path-separator character, represented as a string for convenience.
static charpathSeparatorCharThe system-dependent path-separator character.
static StringseparatorThe system-dependent default name-separator character, represented as a string for convenience.
static charseparatorCharThe system-dependent default name-separator character.

Create file object

ConstructorSummary
File(File parent, String child)Creates a new File instance from a parent abstract pathname and a child pathname string.
File(String pathname)Creates a new File instance by converting the given pathname string into an abstract pathname.
File(String parent, String child)Creates a new File instance from a parent pathname string and a child pathname string.
File(URI uri)Creates a new File instance by converting the given file: URI into an abstract pathname.

Is it executable, readable or writable

ReturnMethodSummary
booleancanExecute()Tests whether the application can execute the file denoted by this abstract pathname.
booleancanRead()Tests whether the application can read the file denoted by this abstract pathname.
booleancanWrite()Tests whether the application can modify the file denoted by this abstract pathname.

Compare two file path

ReturnMethodSummary
intcompareTo(File pathname)Compares two abstract pathnames lexicographically.
booleanequals(Object obj)Tests this abstract pathname for equality with the given object.

Create a file

ReturnMethodSummary
booleancreateNewFile()Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.
static FilecreateTempFile(String prefix, String suffix)Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.
static FilecreateTempFile(String prefix, String suffix, File directory)Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Delete a file

ReturnMethodSummary
booleandelete()Deletes the file or directory denoted by this abstract pathname.
voiddeleteOnExit()Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

Is it a file or a directory

ReturnMethodSummary
booleanisDirectory()Tests whether the file denoted by this abstract pathname is a directory.
booleanisFile()Tests whether the file denoted by this abstract pathname is a normal file.

Whether the file or directory denoted by this abstract pathname exists

ReturnMethodSummary
booleanexists()Tests whether the file or directory denoted by this abstract pathname exists.

Whether this abstract pathname is absolute

ReturnMethodSummary
booleanisAbsolute()Tests whether this abstract pathname is absolute.

Is this file hidden

ReturnMethodSummary
booleanisHidden()Tests whether the file named by this abstract pathname is a hidden file.

Get the file last modified time

ReturnMethodSummary
longlastModified()Returns the time that the file denoted by this abstract pathname was last modified.

Get the file size

ReturnMethodSummary
longlength()Returns the length of the file denoted by this abstract pathname.

Get file path and name

ReturnMethodSummary
FilegetAbsoluteFile()Returns the absolute form of this abstract pathname.
StringgetAbsolutePath()Returns the absolute pathname string of this abstract pathname.
FilegetCanonicalFile()Returns the canonical form of this abstract pathname.
StringgetCanonicalPath()Returns the canonical pathname string of this abstract pathname.
StringgetName()Returns the name of the file or directory denoted by this abstract pathname.
StringgetPath()Converts this abstract pathname into a pathname string.

Get free space, total space, usable space

ReturnMethodSummary
longgetFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name.
longgetTotalSpace()Returns the size of the partition named by this abstract pathname.
longgetUsableSpace()Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.

Get parent file

ReturnMethodSummary
StringgetParent()Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.
FilegetParentFile()Returns the abstract pathname of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Return file in a directory

ReturnMethodSummary
String[]list()Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.
String[]list(FilenameFilter filter)Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
File[]listFiles()Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
File[]listFiles(FileFilter filter)Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
File[]listFiles(FilenameFilter filter)Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
static File[]listRoots()List the available filesystem roots.

Create new directories

ReturnMethodSummary
booleanmkdir()Creates the directory.
booleanmkdirs()Creates the directory, including any necessary but nonexistent parent directories.

Rename file

ReturnMethodSummary
booleanrenameTo(File dest)Renames the file denoted by this abstract pathname.

Change to executable, readable, writable

ReturnMethodSummary
booleansetExecutable(boolean executable)A convenience method to set the owner's execute permission for this abstract pathname.
booleansetExecutable(boolean executable, boolean ownerOnly)Sets the owner's or everybody's execute permission for this abstract pathname.
booleansetLastModified(long time)Sets the last-modified time of the file or directory named by this abstract pathname.
booleansetReadable(boolean readable)A convenience method to set the owner's read permission for this abstract pathname.
booleansetReadable(boolean readable, boolean ownerOnly)Sets the owner's or everybody's read permission for this abstract pathname.
booleansetReadOnly()Marks the file or directory named by this abstract pathname so that only read operations are allowed.
booleansetWritable(boolean writable)A convenience method to set the owner's write permission for this abstract pathname.
booleansetWritable(boolean writable, boolean ownerOnly)Sets the owner's or everybody's write permission for this abstract pathname.

Change last-modified time

ReturnMethodSummary
booleansetLastModified(long time)Sets the last-modified time of the file or directory named by this abstract pathname.

Get string representation of a file location

ReturnMethodSummary
StringtoString()Returns the pathname string of this abstract pathname.

Convert file location to URI and URL

ReturnMethodSummary
URItoURI()Creates a file: URI that represents this abstract pathname.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.