public class File extends Object
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 changesModifier and Type | Class and Description |
---|---|
static interface |
File.FileFilter
Interface for filtering files.
|
static interface |
File.FilenameFilter
Interface to filter filenames.
|
Modifier and Type | Field and Description |
---|---|
static String |
separator |
static char |
separatorChar |
Constructor and Description |
---|
File(File parent,
String path)
Creates a new file in the given parent directory, and subpath.
|
File(String path)
Creates a new file object with given path.
|
File(String dir,
String file)
Creates a new file object in a given directory.
|
File(URI uri)
Creates a new File object from the given URI
|
Modifier and Type | Method and Description |
---|---|
boolean |
canExecute()
Checks if this file is executable.
|
boolean |
createNewFile()
Creates this file as a new blank file in the file system.
|
static File |
createTempFile(String prefix,
String suffix)
Creates a temporary file.
|
boolean |
delete()
Deletes the file described by this object on the file system.
|
boolean |
equals(Object o)
Checks if the given object refers to the same file.
|
boolean |
exists()
Checks if the file described by this object exists on the file system.
|
File |
getAbsoluteFile()
Gets the absolute file - which is always itself, since
isAbsolute() always returns true. |
String |
getAbsolutePath()
Gets the absolute path of the file as a string,
|
long |
getFreeSpace()
Gets the free space on the root file system.
|
String |
getName()
Returns the file name.
|
String |
getParent()
Gets the parent directory path.
|
File |
getParentFile()
Returns the file object for the parent directory.
|
String |
getPath()
Gets the path to the file.
|
long |
getTotalSpace()
Returns the total space on the root file system.
|
long |
getUsableSpace()
Gets the usable space on this file system.
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isAbsolute()
Checks if the path is absolute.
|
boolean |
isDirectory()
Checks if this file is a directory.
|
boolean |
isFile()
Checks if this file object represents a regular file.
|
boolean |
isHidden()
Checks if this is a hidden file.
|
long |
lastModified()
Gets the last modified time as a unix timestamp in milliseconds.
|
long |
length()
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 directory
|
File[] |
listFiles()
Gets a list of child files of this directory.
|
File[] |
listFiles(File.FileFilter ff)
Gets a list of child files of this directory, filtering them using the provided filter.
|
File[] |
listFiles(File.FilenameFilter ff)
Gets a list of child files of this directory, filtered using the provided filter.
|
static File[] |
listRoots()
List the file system roots.
|
boolean |
mkdir()
Attempts to make the directory described by this object.
|
boolean |
mkdirs()
Attempts to make the directory (and all parent directories) of this object.
|
boolean |
renameTo(File f)
Renames the file to the provided file object.
|
String |
toString()
Returns a string representation of the object.
|
URI |
toURI()
Converts this file to a URI.
|
URL |
toURL()
Converts this file to a URL.
|
public static final char separatorChar
public static final String separator
public File(URI uri)
uri
- public File(String path)
path
- The path of the file. Relative or absolute.public File(String dir, String file)
dir
- The parent directory path.file
- The file namepublic String getName()
public String getParent()
public File getParentFile()
public String getPath()
public boolean isAbsolute()
public String getAbsolutePath()
public File getAbsoluteFile()
isAbsolute()
always returns true.public boolean exists()
public boolean isDirectory()
public boolean isFile()
public boolean isHidden()
public long lastModified()
public long length()
public boolean createNewFile() throws IOException
IOException
public boolean delete()
public String[] list()
public String[] list(File.FilenameFilter filter)
filter
- public File[] listFiles()
public File[] listFiles(File.FilenameFilter ff)
ff
- The filter to use.public File[] listFiles(File.FileFilter ff)
ff
- The filter to use to filter output.public boolean mkdir()
public boolean mkdirs()
public boolean renameTo(File f)
f
- The file object that we are renaming the file to.public boolean canExecute()
public static File[] listRoots()
public long getTotalSpace()
public long getFreeSpace()
public long getUsableSpace()
public static File createTempFile(String prefix, String suffix) throws IOException
prefix
- The file name prefix.suffix
- The file name suffixIOException
public boolean equals(Object o)
public int hashCode()
Object
public String toString()
Object
public URL toURL() throws MalformedURLException
MalformedURLException
public URI toURI() throws URISyntaxException
URISyntaxException