|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.xfile.XFile
public class XFile
Instances of this class represent the name of a file or directory. Since only the name of the file is represented, the file itself need not exist.
The XFile object is functionally equivalent to the java.io.File object with the ability to handle not only native pathnames but also URL-style pathnames. URL pathnames have some advantages over native pathnames:
nfs://santa.northpole.org/toys/catalog
file:///C|/java/bin
(a local directory)
nfs://myserver/home/ed
(directory on NFS server)
ftp://ftpsrv/pub/pkg.zip
(file on FTP server)
Base | Relative | Composition |
---|---|---|
file:///a/b/c |
x |
file:///a/b/c/x |
nfs://server/a/b/c |
/y |
nfs://server/y |
nfs://server/a/b/c |
../z |
nfs://server/a/b/z |
file:///a/b/c |
d/. |
nfs://server/a/b/c/d |
file:///a/b/c |
nfs://srv/x |
nfs://srv/x |
Pathnames that are not represented as URL names will be assumed to represent "native" names and XFile will present the same semantics as the java.io.File class.
Constructor Summary | |
---|---|
XFile(java.lang.String name)
Creates a XFile instance that represents the file
whose pathname is the given url argument. |
|
XFile(XFile dir,
java.lang.String name)
Creates a XFile instance that represents the file
with the specified name in the specified directory. |
Method Summary | |
---|---|
boolean |
canRead()
Tests if the application can read from the specified file. |
boolean |
canWrite()
Tests if the application can write to this file. |
boolean |
delete()
Deletes the file specified by this object. |
boolean |
equals(java.lang.Object obj)
Compares this object against the specified object. |
boolean |
exists()
Tests if this XFile exists. |
java.lang.String |
getAbsolutePath()
Returns the absolute pathname of the file represented by this object. |
java.lang.String |
getCanonicalPath()
Returns the canonical form of this XFile object's
pathname. |
XFileExtensionAccessor |
getExtensionAccessor()
Get the XFileExtensionAccessor |
java.lang.String |
getFileSystemName()
Returns the name of the filesystem, the string before the colon of the URL. |
java.lang.String |
getName()
Returns the name of the file represented by this object. |
java.lang.String |
getParent()
Returns the parent part of the pathname of this XFile object, or null if the name
has no parent part. |
java.lang.String |
getPath()
Returns the pathname of the file represented by this object. |
int |
hashCode()
Computes a hashcode for the file. |
boolean |
isAbsolute()
Tests if the file represented by this XFile
object is an absolute pathname. |
boolean |
isDirectory()
Tests if the file represented by this XFile
object is a directory. |
boolean |
isFile()
Tests if the file represented by this XFile
object is a "normal" file. |
long |
lastModified()
Returns the time that the file represented by this XFile object was last modified. |
long |
length()
Returns the length of the file represented by this XFile object. |
java.lang.String[] |
list()
Returns a list of the files in the directory specified by this XFile object. |
java.lang.String[] |
list(XFilenameFilter filter)
Returns a list of the files in the directory specified by this XFile that satisfy the specified filter. |
boolean |
mkdir()
Creates a directory whose pathname is specified by this XFile object. |
boolean |
mkdirs()
Creates a directory whose pathname is specified by this XFile object, including any necessary parent
directories. |
protected XFileAccessor |
newAccessor()
|
boolean |
renameTo(XFile dest)
Renames the file specified by this XFile object to
have the pathname given by the XFile argument. |
java.lang.String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public XFile(java.lang.String name)
XFile
instance that represents the file
whose pathname is the given url argument.
If the the name argument contains the string "://" then it
is assumed to be a URL name. The characters prior to the
colon are assumed to be the filesystem scheme name, e.g.
"file", "nfs", etc. The rest of the URL name is assumed
to be structured according to the Common Internet Scheme
syntax described in
RFC 1738;
an optional location part followed by a hierarchical set
of slash separated directories.
<scheme>://<location>/<path>
name
- the file url
java.lang.NullPointerException
- if the file url
is equal to null
.
public XFile(XFile dir, java.lang.String name)
XFile
instance that represents the file
with the specified name in the specified directory.
If the dir
XFile is null
, or if the
name
string is a full URL, then the single-arg
constructor is used on the name
.
If the dir
XFile represents a native file
and the name
string isAbsolute
then the single-arg constructor is used on the name
.
If the name
is not absolute then the resulting
path is the simple concatenation of the dir
path with the file separator and the name
as
for the two-arg constructor of the File
class.
If the dir
XFile represents a URL name then
the dir
is assumed to be a base URL
and the name
string is evaluated as a
relative URL according to the rules described in
RFC 1808.
Dir | Name | Composition |
---|---|---|
file:///a/b/c |
x |
file:///a/b/c/x |
nfs://server/a/b/c |
/y |
nfs://server/y |
nfs://server/a/b/c |
../z |
nfs://server/a/b/z |
file:///a/b/c |
d/. |
nfs://server/a/b/c/d |
file:///a/b/c |
nfs://srv/x |
nfs://srv/x |
C:\Data\Programs |
myprog.exe |
C:\Data\Programs\myprog.exe |
dir
- the directory.name
- absolute or relative file name or URLMethod Detail |
---|
protected XFileAccessor newAccessor()
public XFileExtensionAccessor getExtensionAccessor()
public java.lang.String getFileSystemName()
public java.lang.String getName()
XFile
object.public java.lang.String getPath()
XFile
object.
If the object is a URL type, the path is the part of the URL following the location, e.g.
new XFile("nfs://location/a/b/c").getPath()
== "a/b/c"
new XFile("file:///a/b/c").getPath()
== "a/b/c"
new XFile("nfs://server/").getPath()
== ""
public java.lang.String getAbsolutePath()
user.dir
contains the current
user directory.
If the object is represented by a URL then return the entire URL string.
XFile
.public java.lang.String getCanonicalPath() throws java.io.IOException
XFile
object's
pathname.
If the object is represented by a URL name then the full
URL is always returned. URL names are always canonical.
For native paths the precise definition of canonical form is system-dependent, but it usually specifies an absolute pathname in which all relative references and references to the current user directory have been completely resolved. The canonical form of a pathname of a nonexistent file may not be defined.
java.io.IOException
- If an I/O error occurs, which
is possible because the construction of the
canonical path may require filesystem queries.public java.lang.String getParent()
XFile
object, or null
if the name
has no parent part.
If the name is a URL then the parent part is the URL with
the last component of the pathname removed. If the URL
has no pathname part, then the URL is returned unchanged.
For native paths the parent part is generally everything
leading up to the last occurrence of the separator character,
although the precise definition is system dependent.
On UNIX, for example, the parent part of "/usr/lib"
is "/usr"
whose parent part is "/"
,
which in turn has no parent.
On Windows platforms, the parent part of "c:\java"
is "c:\"
, which in turn has no parent.
public boolean isAbsolute()
XFile
object is an absolute pathname.
If the object is represented by a URL then true
is always returned.XFile
represents a native name then
the definition of an absolute pathname is system
dependent. For example, on UNIX, a pathname is absolute if its
first character is the separator character.
On Windows platforms,
a pathname is absolute if its first character is an ASCII
'\' or '/', or if it begins with a letter followed by
a colon.
true
if the pathname indicated by the
XFile
object is an absolute pathname;
false
otherwise.public boolean exists()
XFile
exists.
true
if the file specified by this object
exists; false
otherwise.public boolean canWrite()
true
if the application is allowed to
write to a file whose name is specified by this object;
false
otherwise.public boolean canRead()
true
if the file specified by this
object exists and the application can read the file;
false
otherwise.public boolean isFile()
XFile
object is a "normal" file.
A file is "normal" if it is not a directory and, in
addition, satisfies other system-dependent criteria. Any
non-directory file created by a Java application is guaranteed
to be a normal file.
true
if the file specified by this object
exists and is a "normal" file; false
otherwise.public boolean isDirectory()
XFile
object is a directory.
true
if this XFile
exists
and is a directory; false
otherwise.public long lastModified()
XFile
object was last modified.
The return value is system dependent and should only be used to compare with other values returned by last modified. It should not be interpreted as an absolute time.
0L
if the specified file
does not exist.public long length()
XFile
object.
0L
if the specified file does
not exist. The length constitutes the number of bytes
readable via an InputStream. The length value for
a directory is undefined.public boolean renameTo(XFile dest)
XFile
object to
have the pathname given by the XFile
argument.
This object and dest
must represent filesystems
of the same type. For instance: both native or both of
the same URL scheme.
After a successful renameTo, this object continues to
be a valid reference to the file. Only the name
is different.
If the destination filename already exists, it will be replaced.
The application must have permission to modify the source and
destination directory.
dest
- the new filename.
true
if the renaming succeeds;
false
otherwise.public boolean mkdir()
XFile
object.
If any parent directories in the pathname do not
exist, the method will return false.
true
if the directory could be created;
false
otherwise.public boolean mkdirs()
XFile
object, including any necessary parent
directories.
true
if the directory (or directories)
could be created; false
otherwise.public java.lang.String[] list()
XFile
object.
.
" and "..
"
on Unix systems).public java.lang.String[] list(XFilenameFilter filter)
XFile
that satisfy the specified filter.
filter
- a filename filter.
.
" and "..
"
on Unix systems).com.sun.xfilenameFilter
public boolean delete()
true
if the file is successfully deleted;
false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
XFile
object.public boolean equals(java.lang.Object obj)
true
if and only if the argument is
not null
and is a XFile
object whose
pathname is equal to the pathname of this object.
equals
in class java.lang.Object
obj
- the object to compare with.
true
if the objects are the same;
false
otherwise.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |