public class LibgdxFileHandle extends java.lang.Object implements FileHandle
Modifier and Type | Field and Description |
---|---|
com.badlogic.gdx.files.FileHandle |
fileHandle |
Constructor and Description |
---|
LibgdxFileHandle(com.badlogic.gdx.files.FileHandle fileHandle) |
Modifier and Type | Method and Description |
---|---|
FileHandle |
child(java.lang.String name)
Returns a handle to the child with the specified name.
|
void |
copyTo(FileHandle dest)
Copies this file or directory to the specified file or directory.
|
boolean |
delete()
Deletes this file or empty directory and returns success.
|
boolean |
deleteDirectory()
Deletes this file or directory and all children, recursively.
|
void |
emptyDirectory()
Deletes all children of this directory, recursively.
|
void |
emptyDirectory(boolean preserveTree)
Deletes all children of this directory, recursively.
|
boolean |
exists()
Returns true if the file exists.
|
java.lang.String |
extension() |
boolean |
isDirectory()
Returns true if this file is a directory.
|
long |
lastModified()
Returns the last modified time in milliseconds for this file.
|
long |
length()
Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be
determined.
|
FileHandle[] |
list()
Returns the paths to the children of this directory.
|
FileHandle[] |
list(java.io.FileFilter filter)
Returns the paths to the children of this directory that satisfy the specified filter.
|
FileHandle[] |
list(java.io.FilenameFilter filter)
Returns the paths to the children of this directory that satisfy the specified filter.
|
FileHandle[] |
list(java.lang.String suffix)
Returns the paths to the children of this directory with the specified suffix.
|
void |
mkdirs() |
void |
moveTo(FileHandle dest)
Moves this file to the specified file, overwriting the file if it already exists.
|
java.lang.String |
name() |
java.lang.String |
nameWithoutExtension() |
java.lang.String |
normalize()
Returns the path with redundant path elements removed (i.e.
|
FileHandle |
normalizedHandle()
Returns this
FileHandle resolved with a normalised path |
FileHandle |
parent() |
java.lang.String |
path() |
java.lang.String |
pathWithoutExtension() |
java.io.InputStream |
read()
Returns a stream for reading this file as bytes.
|
java.io.BufferedInputStream |
read(int bufferSize)
Returns a buffered stream for reading this file as bytes.
|
byte[] |
readBytes()
Reads the entire file into a byte array.
|
int |
readBytes(byte[] bytes,
int offset,
int size)
Reads the entire file into the byte array.
|
java.io.Reader |
reader()
Returns a reader for reading this file as characters.
|
java.io.BufferedReader |
reader(int bufferSize)
Returns a buffered reader for reading this file as characters.
|
java.io.BufferedReader |
reader(int bufferSize,
java.lang.String charset)
Returns a buffered reader for reading this file as characters.
|
java.io.Reader |
reader(java.lang.String charset)
Returns a reader for reading this file as characters.
|
java.lang.String |
readString()
Reads the entire file into a string using the platform's default charset.
|
java.lang.String |
readString(java.lang.String charset)
Reads the entire file into a string using the specified charset.
|
FileHandle |
sibling(java.lang.String name)
Returns a handle to the sibling with the specified name.
|
FileType |
type() |
java.io.OutputStream |
write(boolean append)
Returns a stream for writing to this file.
|
java.io.OutputStream |
write(boolean append,
int bufferSize)
Returns a buffered stream for writing to this file.
|
void |
write(java.io.InputStream input,
boolean append)
Reads the remaining bytes from the specified stream and writes them to this file.
|
void |
writeBytes(byte[] bytes,
boolean append)
Writes the specified bytes to the file.
|
void |
writeBytes(byte[] bytes,
int offset,
int length,
boolean append)
Writes the specified bytes to the file.
|
java.io.Writer |
writer(boolean append)
Returns a writer for writing to this file using the default charset.
|
java.io.Writer |
writer(boolean append,
java.lang.String charset)
Returns a writer for writing to this file.
|
void |
writeString(java.lang.String string,
boolean append)
Writes the specified string to the file using the default charset.
|
void |
writeString(java.lang.String string,
boolean append,
java.lang.String charset)
Writes the specified string to the file using the specified charset.
|
public LibgdxFileHandle(com.badlogic.gdx.files.FileHandle fileHandle)
public java.lang.String path()
path
in interface FileHandle
public java.lang.String normalize()
FileHandle
normalize
in interface FileHandle
public FileHandle normalizedHandle()
FileHandle
FileHandle
resolved with a normalised pathnormalizedHandle
in interface FileHandle
public java.lang.String name()
name
in interface FileHandle
public java.lang.String extension()
extension
in interface FileHandle
public java.lang.String nameWithoutExtension()
nameWithoutExtension
in interface FileHandle
public java.lang.String pathWithoutExtension()
pathWithoutExtension
in interface FileHandle
public FileType type()
type
in interface FileHandle
public java.io.InputStream read() throws java.io.IOException
FileHandle
read
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.io.BufferedInputStream read(int bufferSize) throws java.io.IOException
FileHandle
read
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.io.Reader reader() throws java.io.IOException
FileHandle
reader
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.io.Reader reader(java.lang.String charset) throws java.io.IOException
FileHandle
reader
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.io.BufferedReader reader(int bufferSize) throws java.io.IOException
FileHandle
reader
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.io.BufferedReader reader(int bufferSize, java.lang.String charset) throws java.io.IOException
FileHandle
reader
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.lang.String readString() throws java.io.IOException
FileHandle
readString
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public java.lang.String readString(java.lang.String charset) throws java.io.IOException
FileHandle
readString
in interface FileHandle
charset
- If null the default charset is used.java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public byte[] readBytes() throws java.io.IOException
FileHandle
readBytes
in interface FileHandle
java.io.IOException
- if the file handle represents a directory, doesn't exist, or could not be read.public int readBytes(byte[] bytes, int offset, int size) throws java.io.IOException
FileHandle
readBytes
in interface FileHandle
bytes
- the array to load the file intooffset
- the offset to start writing bytessize
- the number of bytes to read, see FileHandle.length()
java.io.IOException
public java.io.OutputStream write(boolean append) throws java.io.IOException
FileHandle
write
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public java.io.OutputStream write(boolean append, int bufferSize) throws java.io.IOException
FileHandle
write
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.bufferSize
- The size of the buffer.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public void write(java.io.InputStream input, boolean append) throws java.io.IOException
FileHandle
write
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public java.io.Writer writer(boolean append) throws java.io.IOException
FileHandle
writer
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public java.io.Writer writer(boolean append, java.lang.String charset) throws java.io.IOException
FileHandle
writer
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.charset
- May be null to use the default charset.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public void writeString(java.lang.String string, boolean append) throws java.io.IOException
FileHandle
writeString
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public void writeString(java.lang.String string, boolean append, java.lang.String charset) throws java.io.IOException
FileHandle
writeString
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.charset
- May be null to use the default charset.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public void writeBytes(byte[] bytes, boolean append) throws java.io.IOException
FileHandle
writeBytes
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public void writeBytes(byte[] bytes, int offset, int length, boolean append) throws java.io.IOException
FileHandle
writeBytes
in interface FileHandle
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.java.io.IOException
- if this file handle represents a directory, if it is a FileType.INTERNAL
file, or if it could not be written.public FileHandle[] list() throws java.io.IOException
FileHandle
FileType.INTERNAL
handle to a directory on the classpath will return a zero length
array.list
in interface FileHandle
java.io.IOException
public FileHandle[] list(java.io.FileFilter filter) throws java.io.IOException
FileHandle
FileType.INTERNAL
handle to a directory on the
classpath will return a zero length array.list
in interface FileHandle
filter
- the FileFilter
to filter filesjava.io.IOException
public FileHandle[] list(java.io.FilenameFilter filter) throws java.io.IOException
FileHandle
FileType.INTERNAL
handle to a directory on the
classpath will return a zero length array.list
in interface FileHandle
filter
- the FilenameFilter
to filter filesjava.io.IOException
public FileHandle[] list(java.lang.String suffix) throws java.io.IOException
FileHandle
FileType.INTERNAL
handle to a directory on the classpath
will return a zero length array.list
in interface FileHandle
java.io.IOException
public boolean isDirectory()
FileHandle
FileType.INTERNAL
handle to an empty directory will return false. On the desktop, an FileType.INTERNAL
handle to a directory on the classpath will return false.isDirectory
in interface FileHandle
public FileHandle child(java.lang.String name)
FileHandle
child
in interface FileHandle
public FileHandle sibling(java.lang.String name)
FileHandle
sibling
in interface FileHandle
public FileHandle parent()
parent
in interface FileHandle
public void mkdirs() throws java.io.IOException
mkdirs
in interface FileHandle
java.io.IOException
- if this file handle is a FileType.INTERNAL
file.public boolean exists()
FileHandle
FileType.INTERNAL
handle to a
directory will always return false. Note that this can be very slow for internal files on Android!exists
in interface FileHandle
public boolean delete() throws java.io.IOException
FileHandle
delete
in interface FileHandle
java.io.IOException
- if this file handle is a FileType.INTERNAL
file.public boolean deleteDirectory() throws java.io.IOException
FileHandle
deleteDirectory
in interface FileHandle
java.io.IOException
- if this file handle is a FileType.INTERNAL
file.public void emptyDirectory() throws java.io.IOException
FileHandle
emptyDirectory
in interface FileHandle
java.io.IOException
- if this file handle is a FileType.INTERNAL
file.public void emptyDirectory(boolean preserveTree) throws java.io.IOException
FileHandle
emptyDirectory
in interface FileHandle
java.io.IOException
- if this file handle is a FileType.INTERNAL
file.public void copyTo(FileHandle dest) throws java.io.IOException
FileHandle
FileHandle.mkdirs()
is called on the destination's parent and this file is copied into it with a new name. If
this handle is a directory, then 1) if the destination is a file, IOException is thrown, or 2) if the destination is
a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't
exist, FileHandle.mkdirs()
is called on the destination and this directory is copied into it recursively.copyTo
in interface FileHandle
java.io.IOException
- if the destination file handle is a FileType.INTERNAL
file, or copying failed.public void moveTo(FileHandle dest) throws java.io.IOException
FileHandle
moveTo
in interface FileHandle
java.io.IOException
- if the source or destination file handle is a FileType.INTERNAL
file.public long length()
FileHandle
length
in interface FileHandle
public long lastModified()
FileHandle
FileType.INTERNAL
files.lastModified
in interface FileHandle