public class XdevFile extends File
File
,
Serialized FormpathSeparator, pathSeparatorChar, separator, separatorChar
Constructor and Description |
---|
XdevFile(File path)
Creates a new
XdevFile instance by converting the given pathname
string into an abstract pathname. |
XdevFile(File parent,
String child)
Creates a new
XdevFile instance from a parent abstract pathname
and a child pathname string. |
XdevFile(String pathname)
Creates a new
XdevFile instance by converting the given pathname
string into an abstract pathname. |
XdevFile(String parent,
String child)
Creates a new
XdevFile instance from a parent pathname string and
a child pathname string. |
XdevFile(URI uri)
Creates a new
XdevFile instance by converting the given
file: URI into an abstract pathname. |
Modifier and Type | Method and Description |
---|---|
XdevFile |
copyTo(File dest)
Copies this file to
dest .If this file is a directory: dest has to be a directory or an IOExeption
is thrown
a new directory with src 's name is created in
dest and this file's content is copied to the new directory
else if this is a file:
if dest is a directory, this file is copied to
dest to a file with the same name
else if dest is a file, dest is overwritten
with this file's content
|
boolean |
createDirectory()
This method is a alias for
File.mkdirs() . |
boolean |
createFile()
Atomically creates a new, empty file named by
this abstract
pathname if and only if a file with this name does not yet exist. |
String |
createHash(String algorithm)
Creates a hash value of this file using the specified algorithm.
|
XdevList<XdevFile> |
getChildren()
Returns a sorted
XdevList of child files of this folder.The directory's parent directory are not included in the result. |
static FileSystemView |
getFileSystemView()
Returns the gateway to the file system.
|
XdevDate |
getLastModified()
Return a
XdevDate with the time of the last modification of this
file. |
XdevFile |
getParentXdevFile()
Return the
XdevFile of the parent directory. |
long |
getSize()
This method is a alias for
File.length() . |
String |
getSystemDisplayName()
Name of a file, directory, or folder as it would be displayed in a system
file browser.
|
String |
getSystemDisplaySize()
Returns this file's size in a human readable form.
|
Icon |
getSystemIcon()
Icon for this
XdevFile as it would be displayed in a system file
browser. |
XdevImage |
getSystemImage()
|
static XdevFile[] |
getSystemRoots()
Returns all root files on this system.
|
String |
getSystemTypeDescription()
Type description for a file, directory, or folder as it would be
displayed in a system file browser.
|
boolean |
isChildOf(XdevFile parent)
Tests if
parent is a parent or a parent's parent directory
of this file. |
boolean |
isParentOf(XdevFile child)
Tests if this file is a parent or a parent's parent directory of
child . |
InputStream |
openInputStream()
Creates a
InputStream by opening a connection to this
XdevFile . |
OutputStream |
openOutputStream()
This method is a alias for
openOutputStream(false) . |
OutputStream |
openOutputStream(boolean append)
Creates
OutputStream to write to the file represented by the
specified XdevFile object. |
Reader |
openReader()
|
Reader |
openReader(Charset charset)
|
Reader |
openReader(String charsetName)
|
Writer |
openWriter()
This method is a alias for
openWriter(false) . |
Writer |
openWriter(boolean append)
|
Writer |
openWriter(boolean append,
Charset charset)
|
Writer |
openWriter(boolean append,
String charsetName)
|
Writer |
openWriter(Charset charset)
|
Writer |
openWriter(String charsetName)
|
byte[] |
readData()
Reads the contents of this file into a byte array.
|
String |
readString()
Reads from this file and stores results in a string.
|
String |
readString(String charsetName)
Reads from this file and stores results in a string.
|
boolean |
setLastModified(XdevDate date)
Sets the last-modified time of the file.
|
static void |
sort(List<? extends File> files)
Sorts a list of files in the underlying operating system's manner.
|
static XdevFile[] |
toXdevFile(File... files)
Converts an array of java.io.Files to an array of XdevFiles;
|
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, delete, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
public XdevFile(File path) throws NullPointerException
XdevFile
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.path
- a file with a absolute pathNullPointerException
- If the path
argument is null
public XdevFile(File parent, String child) throws NullPointerException
XdevFile
instance from a parent abstract pathname
and a child pathname string.
If parent
is null
then the new XdevFile
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 XdevFile
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 stringNullPointerException
- If child
is null
public XdevFile(String parent, String child) throws NullPointerException
XdevFile
instance from a parent pathname string and
a child pathname string.
If parent
is null
then the new XdevFile
instance is created as if by invoking the single-argument
File
constructor on the given child
pathname
string.
Otherwise the parent
pathname string 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 string then the
new XdevFile
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 pathname stringchild
- The child pathname stringNullPointerException
- If child
is null
public XdevFile(String pathname) throws NullPointerException
XdevFile
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 stringNullPointerException
- If the pathname
argument is null
public XdevFile(URI uri) throws NullPointerException, IllegalArgumentException
XdevFile
instance by converting the given
file: URI into an abstract pathname.
The exact form of a file: URI is system-dependent, hence the transformation performed by this constructor is also system-dependent.
For a given abstract pathname f it is guaranteed that
new File( f .so long as the original abstract pathname, the URI, and the new abstract pathname are all created in (possibly different invocations of) the same Java virtual machine. This relationship typically does not hold, however, when a file: URI that is created in a virtual machine on one operating system is converted into an abstract pathname in a virtual machine on a different operating system.toURI
()).equals( f .getAbsoluteFile
())
uri
- An absolute, hierarchical URI with a scheme equal to
"file", a non-empty path component, and undefined
authority, query, and fragment componentsNullPointerException
- If uri is nullIllegalArgumentException
- If the preconditions on the parameter do not holdFile.toURI()
,
URI
public static XdevFile[] toXdevFile(File... files)
files
- the array to convertpublic XdevDate getLastModified() throws SecurityException
XdevDate
with the time of the last modification of this
file.XdevDate
with the time of the last modification of this
file.SecurityException
- If a security manager exists and its
SecurityManager.checkRead(java.lang.String)
method denies read access to the filepublic boolean setLastModified(XdevDate date) throws NullPointerException
date
- the XdevDate
is set as the last modification of this
file.true
if and only if the operation succeeded;
false
otherwiseNullPointerException
- If date is nullpublic long getSize() throws SecurityException
File.length()
.0L
if the file does not exist. Some
operating systems may return 0L
for pathnames
denoting system-dependent entities such as devices or pipes.SecurityException
- If a security manager exists and its
SecurityManager.checkRead(java.lang.String)
method denies read access to the filepublic XdevFile getParentXdevFile() throws NullPointerException
XdevFile
of the parent directory.XdevFile
of the parent directoryNullPointerException
- If the XdevFile
does not have a parent directorygetChildren()
public boolean isParentOf(XdevFile child)
child
.child
- the may-be-childchild
, false
otherwisepublic boolean isChildOf(XdevFile parent)
parent
is a parent or a parent's parent directory
of this file.parent
- the may-be-parentparent
is a parent or a parent's parent
directory of this file, false
otherwisepublic XdevList<XdevFile> getChildren() throws SecurityException
XdevList
of child files of this folder.XdevList
of child files in that folder.SecurityException
- If a security manager exists and its
SecurityManager.checkRead(java.lang.String)
method denies read access to the directorygetParentXdevFile()
public static void sort(List<? extends File> files)
files
- the files to sortpublic boolean createFile() throws SecurityException
this
abstract
pathname if and only if a file with this name does not yet exist. The
check for the existence of the file and the creation of the file if it
does not exist are a single operation that is atomic with respect to all
other filesystem activities that might affect the file.true
if the named file does not exist and was
successfully created; false
if the named file
already exists or any problem occurred.SecurityException
- If a security manager exists and its
SecurityManager.checkWrite(java.lang.String)
method denies write access to the fileFile.createNewFile()
public boolean createDirectory() throws SecurityException
File.mkdirs()
.true
if and only if the directory was created, along
with all necessary parent directories; false
otherwiseSecurityException
- If a security manager exists and its
SecurityManager.checkRead(java.lang.String)
method does not permit verification of the existence of the
named directory and all necessary parent directories; or if
the
SecurityManager.checkWrite(java.lang.String)
method does not permit the named directory and all necessary
parent directories to be createdpublic String getSystemDisplayName()
XdevFile
is not available, the
name of this XdevFile
is returned.String
the file name as it would be displayed by a
native file chooser; null
if name is not availablepublic String getSystemDisplaySize()
public Icon getSystemIcon()
XdevFile
as it would be displayed in a system file
browser. If the icon for this XdevFile
is not available,
null
is returned.Icon
as it would be displayed by a native file
chooser; null
if icon is not availablepublic XdevImage getSystemImage()
public String getSystemTypeDescription()
null
if no native information is
available.public Reader openReader() throws IOException
Reader
IOException
- If the file does not exist, is a directory rather than a
regular file, or for some other reason cannot be opened for
reading.public Reader openReader(String charsetName) throws IOException, UnsupportedEncodingException
charsetName
- The name of a supported Charset
Reader
IOException
- If the file does not exist, is a directory rather than a
regular file, or for some other reason cannot be opened for
reading.UnsupportedEncodingException
- If the named charset is not supported.public Reader openReader(Charset charset) throws IOException
charset
- A Charset
Reader
IOException
- if the file does not exist, is a directory rather than a
regular file, or for some other reason cannot be opened for
reading.public Writer openWriter() throws IOException
openWriter(false)
.Writer
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonopenWriter(boolean)
public Writer openWriter(boolean append) throws IOException
Writer
object to write on this XdevFile
. If
append
is true
, then bytes will be written to
the end of the file rather than the beginning.append
- if true
, then bytes will be written to the end of
the file rather than the beginningWriter
object to write on this XdevFile
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonpublic Writer openWriter(String charsetName) throws IOException, UnsupportedEncodingException
charsetName
- The name of a supported Charset
Writer
object to write on this XdevFile
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonUnsupportedEncodingException
- If the named charset is not supported.public Writer openWriter(boolean append, String charsetName) throws IOException, UnsupportedEncodingException
Writer
object to write on this XdevFile
using the given charset. If append
is true
,
then bytes will be written to the end of the file rather than the
beginning.append
- if true
, then bytes will be written to the end of
the file rather than the beginningcharsetName
- The name of a supported Charset
Writer
object to write on this XdevFile
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonUnsupportedEncodingException
- If the named charset is not supported.public Writer openWriter(Charset charset) throws IOException
charset
- A Charset
Writer
object to write on this XdevFile
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonpublic Writer openWriter(boolean append, Charset charset) throws IOException
Writer
object to write on this XdevFile
using the given charset. If append
is true
,
then bytes will be written to the end of the file rather than the
beginning.append
- if true
, then bytes will be written to the end of
the file rather than the beginningcharset
- A Charset
Writer
object to write on this XdevFile
IOException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonpublic InputStream openInputStream() throws FileNotFoundException, SecurityException
InputStream
by opening a connection to this
XdevFile
. A new FileDescriptor
object is created to
represent this file connection.
First, if there is a security manager, its
SecurityManager.checkRead(String)
method is called with the path
represented by the this XdevFile
argument as its argument.
If the named file does not exist, is a directory rather than a regular
file, or for some other reason cannot be opened for reading then a
FileNotFoundException
is thrown.
InputStream
FileNotFoundException
- if the file does not exist, is a directory rather than a
regular file, or for some other reason cannot be opened
for reading.SecurityException
- if a security manager exists and its
SecurityManager.checkRead(String)
method denies
read access to the file.InputStream
,
FileInputStream
public OutputStream openOutputStream() throws FileNotFoundException, SecurityException
openOutputStream(false)
.OutputStream
to write into this XdevFile
FileNotFoundException
- if the file exists but is a directory rather than a
regular file, does not exist but cannot be created, or
cannot be opened for any other reasonSecurityException
- if a security manager exists and its
SecurityManager.checkWrite(String)
method denies
write access to the file.openOutputStream(boolean)
public OutputStream openOutputStream(boolean append) throws FileNotFoundException, SecurityException
OutputStream
to write to the file represented by the
specified XdevFile
object. If the second argument is
true
, then bytes will be written to the end of the file
rather than the beginning. A new FileDescriptor
object is created
to represent this file connection.
First, if there is a security manager, its
SecurityManager.checkWrite(String)
method is called with the path
represented by the XdevFile
argument as its argument.
If the file exists but is a directory rather than a regular file, does
not exist but cannot be created, or cannot be opened for any other reason
then a FileNotFoundException
is thrown.
append
- if true
, then bytes will be written to the end of
the file rather than the beginningOutputStream
to write into the XdevFile
FileNotFoundException
- if the file exists but is a directory rather than a regular
file, does not exist but cannot be created, or cannot be
opened for any other reasonSecurityException
- if a security manager exists and its
SecurityManager.checkWrite(String)
method denies
write access to the file.FileOutputStream
public byte[] readData() throws IOException
IOException
- if an I/O error occurspublic String readString() throws IOException
IOException
public String readString(String charsetName) throws IOException
charsetName
- a name of a character set to useIOException
- if an I/O error occurspublic XdevFile copyTo(File dest) throws IOException
dest
.dest
has to be a directory or an IOExeption
is thrownsrc
's name is created in
dest
and this file's content is copied to the new directorydest
is a directory, this file is copied to
dest
to a file with the same name
dest
is a file, dest
is overwritten
with this file's contentdest
- the destination file or directoryIOException
- if an I/O error occurspublic String createHash(String algorithm) throws IOException
algorithm
- the name of the hash algorithm to use. See Appendix A in the
Java Cryptography Architecture API Specification &
Reference for information about standard algorithm names.String
.IOException
public static FileSystemView getFileSystemView()
public static XdevFile[] getSystemRoots()
XdevFile[] roots = XdevFile.getSystemRoots();
Copyright © 2003–2021 XDEV Software. All rights reserved.