|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jcontrol.io.File
public class File
An abstract representation of file and directory pathnames.
User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames. An abstract pathname has two components:
"usba0"
for the USB root
directory, or "roma0"
for the internal ROMFS, and
When an abstract pathname is converted into a
pathname string, each name is separated from the next by a single copy of
the default separator character "/"
. The default name-separator
is made available in the public static fields
and SEPARATOR
of this class.
When a pathname string is converted into an abstract pathname, the names
within it may be separated by the default name-separator character.
SEPARATOR_CHAR
A pathname, whether abstract or in string form, may be always absolute. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes.
The prefix concept is used to handle different devices, like USB stick or ROM-Filesystem, as follows:
":"
(
example: "usba0:dir/subdir/image.jpg
).
Instances of the File
class are immutable; that is, once
created, the abstract pathname represented by a File
object
will never change.
Field Summary | |
---|---|
static String |
SEPARATOR
The system-dependent default name-separator character, represented as a string for convenience. |
static char |
SEPARATOR_CHAR
The system-dependent default name-separator character. |
static String |
SEPARATOR_URI
|
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
boolean |
canRead()
NOTE: Not Supported Tests whether the application can read the file denoted by this abstract pathname. |
boolean |
canWrite()
NOTE: Not Supported Tests whether the application can modify to the file denoted by this abstract pathname. |
boolean |
createNewFile()
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. |
boolean |
delete()
Deletes the file denoted by this abstract pathname. |
boolean |
exists()
Tests whether the file or directory denoted by this abstract pathname exists. |
protected void |
finalize()
Free internal data structures used by this file object. |
String |
getCanonicalPath()
Returns the canonical pathname string of this abstract pathname. |
String |
getName()
Returns the name of the file or directory denoted by this abstract pathname. |
String |
getPath()
Converts this abstract pathname into a pathname string. |
boolean |
isDirectory()
Tests whether the file denoted by this abstract pathname is a directory. |
boolean |
isFile()
Tests whether the file denoted by this abstract pathname is a normal file. |
int |
length()
Returns the length of the file denoted by this abstract pathname. |
String[] |
list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname. |
File[] |
listFiles()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname. |
static File[] |
listRoots()
List the available filesystem roots. |
String |
toString()
Returns the pathname string of this abstract pathname. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, notifyAll, wait |
Field Detail |
---|
public static final String SEPARATOR_URI
public static final char SEPARATOR_CHAR
java.lang.System#getProperty(java.lang.String)
,
Constant Field Valuespublic static final String SEPARATOR
SEPARATOR_CHAR
.
Constructor Detail |
---|
public File(String pathname)
File
instance by converting the given
pathname string into an abstract pathname. If the given string is
the empty string, then the result is the empty abstract pathname.
pathname
- A pathname string
NullPointerException
- If the pathname
argument is null
public File(File parent, String child)
File
instance from a parent abstract
pathname and a child pathname string.
If parent
is null
then the new
File
instance is created as if by invoking the
single-argument File
constructor on the given
child
pathname string.
Otherwise the parent
abstract pathname is taken to
denote a directory, and the child
pathname string is taken
to denote either a directory or a file. If the child
pathname string is absolute then it is converted into a relative
pathname in a system-dependent way. If parent
is the empty
abstract pathname then the new File
instance is created by
converting child
into an abstract pathname and resolving
the result against a system-dependent default directory. Otherwise each
pathname string is converted into an abstract pathname and the child
abstract pathname is resolved against the parent.
parent
- The parent abstract pathnamechild
- The child pathname string
NullPointerException
- If child
is null
Method Detail |
---|
public String getName()
public String getPath()
default name-separator character
to
separate the names in the name sequence.
public String getCanonicalPath()
A canonical pathname is both absolute and unique. The precise
definition of canonical form is system-dependent. This method first
converts this pathname to absolute form if necessary, as if by invoking the
#getAbsolutePath
method, and then maps it to its unique form in a
system-dependent way. This typically involves removing redundant names
such as "." and ".." from the pathname, resolving
symbolic links (on UNIX platforms), and converting drive letters to a
standard case (on Microsoft Windows platforms).
Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted.
IOException
- If an I/O error occurs, which is possible because the
construction of the canonical pathname may require
filesystem queriespublic boolean canRead()
NOTE: Not Supported
Tests whether the application can read the file denoted by this abstract pathname.
true
if and only if the file specified by this
abstract pathname exists and can be read by the
application; false
otherwisepublic boolean canWrite()
NOTE: Not Supported
Tests whether the application can modify to the file denoted by this abstract pathname.
true
if and only if the file system actually
contains a file denoted by this abstract pathname and
the application is allowed to write to the file;
false
otherwise.public boolean exists()
true
if and only if the file or directory denoted
by this abstract pathname exists; false
otherwisepublic boolean isDirectory()
true
if and only if the file denoted by this
abstract pathname exists and is a directory;
false
otherwisepublic boolean isFile()
true
if and only if the file denoted by this
abstract pathname exists and is a normal file;
false
otherwisepublic int length()
0L
if the file does not existpublic boolean createNewFile() throws IOException
Note: this method should not be used for file-locking, as
the resulting protocol cannot be made to work reliably. The
FileLock
facility should be used instead.
true
if the named file does not exist and was
successfully created; false
if the named file
already exists
IOException
- If an I/O error occurredpublic boolean delete()
true
if and only if the file is
successfully deleted; false
otherwisepublic String[] list()
If this abstract pathname does not denote a directory, then this
method returns null
. Otherwise an array of strings is
returned, one for each file or directory in the directory. Names
denoting the directory itself and the directory's parent directory are
not included in the result. Each string is a file name rather than a
complete path.
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
null
if
this abstract pathname does not denote a directory, or if an
I/O error occurs.public File[] listFiles()
If this abstract pathname does not denote a directory, then this
method returns null
. Otherwise an array of
File
objects is returned, one for each file or directory in
the directory. Pathnames denoting the directory itself and the
directory's parent directory are not included in the result. Each
resulting abstract pathname is constructed from this abstract pathname
using the
constructor. Therefore if this pathname
is absolute then each resulting pathname is absolute; if this pathname
is relative then each resulting pathname will be relative to the same
directory.
File(File, String)
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
null
if this abstract pathname
does not denote a directory, or if an I/O error occurs.public static File[] listRoots()
A particular Java platform may support zero or more
hierarchically-organized file systems. Each file system has a
root
directory from which all other files in that file
system can be reached. Windows platforms, for example, have a root
directory for each active drive; UNIX platforms have a single root
directory, namely "/"
. JControl platforms have a root
directory for each existing filesystem, etc. "usba0"
or
"roma0"
. The set of available filesystem
roots is affected by various system-level operations such the insertion
or ejection of removable media and the disconnecting or unmounting of
physical or virtual disk drives.
This method returns an array of File
objects that
denote the root directories of the available filesystem roots. It is
guaranteed that the canonical pathname of any file physically present on
the local machine will begin with one of the roots returned by this
method.
File
objects denoting the available
filesystem roots, or null
if the set of roots
could not be determined. The array will be empty if there are
no filesystem roots.public String toString()
getPath()
method.
toString
in class Object
protected void finalize()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |