Class File
java.io.File making it almost into a "drop in" replacement.
It is placed in a different package because it is incompatible to java.io.File by definition. It is useful
in getting some simple code to work without too many changes-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for filtering files.static interfaceInterface to filter filenames. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new file in the given parent directory, and subpath.Creates a new file object with given path.Creates a new file object in a given directory.Creates a new File object from the given URI -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if this file is executable.booleanCreates this file as a new blank file in the file system.static FilecreateTempFile(String prefix, String suffix) Creates a temporary file.booleandelete()Deletes the file described by this object on the file system.booleanChecks if the given object refers to the same file.booleanexists()Checks if the file described by this object exists on the file system.Gets the absolute file - which is always itself, since#isAbsolute()always returns true.Gets the absolute path of the file as a string,longGets the free space on the root file system.getName()Returns the file name.Gets the parent directory path.Returns the file object for the parent directory.getPath()Gets the path to the file.longReturns the total space on the root file system.longGets the usable space on this file system.inthashCode()booleanChecks if the path is absolute.booleanChecks if this file is a directory.booleanisFile()Checks if this file object represents a regular file.booleanisHidden()Checks if this is a hidden file.longGets the last modified time as a unix timestamp in milliseconds.longlength()Gets the file size in bytes.String[]list()Returns the list of child files of this directory.String[]list(File.FilenameFilter filter) Returns list of child files of this directoryFile[]Gets a list of child files of this directory.File[]Gets a list of child files of this directory, filtering them using the provided filter.File[]Gets a list of child files of this directory, filtered using the provided filter.static File[]List the file system roots.booleanmkdir()Attempts to make the directory described by this object.booleanmkdirs()Attempts to make the directory (and all parent directories) of this object.booleanRenames the file to the provided file object.toString()toURI()Converts this file to a URI.toURL()Converts this file to a URL.
-
Field Details
-
separatorChar
public static final char separatorChar- See Also:
-
separator
- See Also:
-
-
Constructor Details
-
File
Creates a new File object from the given URI
Parameters
uri
-
File
Creates a new file object with given path. Paths that do not begin with the "file:" prefix will automatically be prefixed with the app home path.
Parameters
path: The path of the file. Relative or absolute.
-
File
-
File
-
-
Method Details
-
listRoots
List the file system roots. -
createTempFile
Creates a temporary file.
Parameters
-
prefix: The file name prefix. -
suffix: The file name suffix
Returns
The resulting temporary file.
Throws
IOException
- Throws:
IOException
-
-
getName
Returns the file name.
Returns
The file name.
-
getParent
Gets the parent directory path.
Returns
The parent directory path.
-
getParentFile
Returns the file object for the parent directory. -
getPath
Gets the path to the file. -
isAbsolute
public boolean isAbsolute()Checks if the path is absolute. This always returns true as all File objects use absolute paths - even if they were created with relative paths. Relative paths are automatically prefixed with the app home directory path. -
getAbsolutePath
Gets the absolute path of the file as a string, -
getAbsoluteFile
Gets the absolute file - which is always itself, since
#isAbsolute()always returns true.Returns
The same file object.
-
exists
public boolean exists()Checks if the file described by this object exists on the file system. -
isDirectory
public boolean isDirectory()Checks if this file is a directory. -
isFile
public boolean isFile()Checks if this file object represents a regular file. -
isHidden
public boolean isHidden()Checks if this is a hidden file. -
lastModified
public long lastModified()Gets the last modified time as a unix timestamp in milliseconds. -
length
public long length()Gets the file size in bytes.
Returns
The file size in bytes.
-
createNewFile
Creates this file as a new blank file in the file system.
Returns
True if it succeeds.
Throws
IOException
- Throws:
IOException
-
delete
public boolean delete()Deletes the file described by this object on the file system.
Returns
True if delete succeeds.
-
list
Returns the list of child files of this directory. -
list
Returns list of child files of this directory
Parameters
filter
-
listFiles
Gets a list of child files of this directory. -
listFiles
Gets a list of child files of this directory, filtered using the provided filter.
Parameters
ff: The filter to use.
-
listFiles
Gets a list of child files of this directory, filtering them using the provided filter.
Parameters
ff: The filter to use to filter output.
-
mkdir
public boolean mkdir()Attempts to make the directory described by this object.
Returns
True on success.
-
mkdirs
public boolean mkdirs()Attempts to make the directory (and all parent directories) of this object.
Returns
True on success.
-
renameTo
Renames the file to the provided file object.
Parameters
f: The file object that we are renaming the file to.
Returns
True on success.
-
canExecute
public boolean canExecute()Checks if this file is executable. -
getTotalSpace
public long getTotalSpace()Returns the total space on the root file system. -
getFreeSpace
public long getFreeSpace()Gets the free space on the root file system. -
getUsableSpace
public long getUsableSpace()Gets the usable space on this file system. -
equals
-
hashCode
-
toString
-
toURL
Converts this file to a URL.
Throws
MalformedURLException
- Throws:
MalformedURLException
-
toURI
Converts this file to a URI.
Throws
URISyntaxException
- Throws:
URISyntaxException
-