File

public class File extends Object
implements Serializable Comparable<File>

An "abstract" representation of a file system entity identified by a pathname. The pathname may be absolute (relative to the root directory of the file system) or relative to the current directory in which the program is running.

The actual file referenced by a File may or may not exist. It may also, despite the name File, be a directory or other non-regular file.

This class provides limited functionality for getting/setting file permissions, file type, and last modified time.

On Android strings are converted to UTF-8 byte sequences when sending filenames to the operating system, and byte sequences returned by the operating system (from the various list methods) are converted to strings by decoding them as UTF-8 byte sequences.

Field Summary

public static final String pathSeparator The system-dependent string used to separate components in search paths (":").
public static final char pathSeparatorChar The system-dependent character used to separate components in search paths (':').
public static final String separator The system-dependent string used to separate components in filenames ('/').
public static final char separatorChar The system-dependent character used to separate components in filenames ('/').

Public Constructor Summary

File(File dir, String name)
Constructs a new file using the specified directory and name.
File(String path)
Constructs a new file using the specified path.
File(String dirPath, String name)
Constructs a new File using the specified directory path and file name, placing a path separator between the two.
File(URI uri)
Constructs a new File using the path of the specified URI.

Public Method Summary

boolean
canExecute()
Tests whether or not this process is allowed to execute this file.
boolean
canRead()
Indicates whether the current context is allowed to read from this file.
boolean
canWrite()
Indicates whether the current context is allowed to write to this file.
int
compareTo(File another)
Returns the relative sort ordering of the paths for this file and the file another.
boolean
createNewFile()
Creates a new, empty file on the file system according to the path information stored in this file.
static File
createTempFile(String prefix, String suffix, File directory)
Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.
static File
createTempFile(String prefix, String suffix)
Creates an empty temporary file using the given prefix and suffix as part of the file name.
boolean
delete()
Deletes this file.
void
deleteOnExit()
Schedules this file to be automatically deleted when the VM terminates normally.
boolean
equals(Object obj)
Compares obj to this file and returns true if they represent the same object using a path specific comparison.
boolean
exists()
Returns a boolean indicating whether this file can be found on the underlying file system.
File
getAbsoluteFile()
Returns a new file constructed using the absolute path of this file.
String
getAbsolutePath()
Returns the absolute path of this file.
File
getCanonicalFile()
Returns a new file created using the canonical path of this file.
String
getCanonicalPath()
Returns the canonical path of this file.
long
getFreeSpace()
Returns the number of free bytes on the partition containing this path.
String
getName()
Returns the name of the file or directory represented by this file.
String
getParent()
Returns the pathname of the parent of this file.
File
getParentFile()
Returns a new file made from the pathname of the parent of this file.
String
getPath()
Returns the path of this file.
long
getTotalSpace()
Returns the total size in bytes of the partition containing this path.
long
getUsableSpace()
Returns the number of usable free bytes on the partition containing this path.
int
hashCode()
Returns an integer hash code for the receiver.
boolean
isAbsolute()
Indicates if this file's pathname is absolute.
boolean
isDirectory()
Indicates if this file represents a directory on the underlying file system.
boolean
isFile()
Indicates if this file represents a file on the underlying file system.
boolean
isHidden()
Returns whether or not this file is a hidden file as defined by the operating system.
long
lastModified()
Returns the time when this file was last modified, measured in milliseconds since January 1st, 1970, midnight.
long
length()
Returns the length of this file in bytes.
String[]
list(FilenameFilter filter)
Gets a list of the files in the directory represented by this file.
String[]
list()
Returns an array of strings with the file names in the directory represented by this file.
File[]
listFiles()
Returns an array of files contained in the directory represented by this file.
File[]
listFiles(FileFilter filter)
Gets a list of the files in the directory represented by this file.
<