|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.files.FileHandle
public class FileHandle
Represents a file or directory on the filesystem, classpath, Android SD card, or Android assets directory. FileHandles are
created via a Files
instance.
Field Summary | |
---|---|
protected java.io.File |
file
|
protected Files.FileType |
type
|
Constructor Summary | |
---|---|
protected |
FileHandle()
|
|
FileHandle(java.io.File file)
Creates a new absolute FileHandle for the File . |
protected |
FileHandle(java.io.File file,
Files.FileType type)
|
|
FileHandle(java.lang.String fileName)
Creates a new absolute FileHandle for the file name. |
protected |
FileHandle(java.lang.String fileName,
Files.FileType type)
|
Method Summary | |
---|---|
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. |
boolean |
exists()
Returns true if the file exists. |
java.lang.String |
extension()
|
java.io.File |
file()
Returns a java.io.File that represents this file handle. |
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.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()
|
FileHandle |
parent()
|
java.lang.String |
path()
|
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. |
static FileHandle |
tempDirectory(java.lang.String prefix)
|
static FileHandle |
tempFile(java.lang.String prefix)
|
java.lang.String |
toString()
|
Files.FileType |
type()
|
java.io.OutputStream |
write(boolean append)
Returns a 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 as UTF-8. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.io.File file
protected Files.FileType type
Constructor Detail |
---|
protected FileHandle()
public FileHandle(java.lang.String fileName)
Files
interface instead.
fileName
- the filename.public FileHandle(java.io.File file)
File
. Use this for tools on the desktop that don't need any of the
backends. Do not use this constructor in case you write something cross-platform. Use the Files
interface instead.
file
- the file.protected FileHandle(java.lang.String fileName, Files.FileType type)
protected FileHandle(java.io.File file, Files.FileType type)
Method Detail |
---|
public java.lang.String path()
public java.lang.String name()
public java.lang.String extension()
public java.lang.String nameWithoutExtension()
public Files.FileType type()
public java.io.File file()
Files.FileType.Absolute
and Files.FileType.External
file handles.
public java.io.InputStream read()
public java.io.BufferedInputStream read(int bufferSize)
public java.io.Reader reader()
public java.io.Reader reader(java.lang.String charset)
public java.io.BufferedReader reader(int bufferSize)
public java.io.BufferedReader reader(int bufferSize, java.lang.String charset)
public java.lang.String readString()
public java.lang.String readString(java.lang.String charset)
public byte[] readBytes()
public int readBytes(byte[] bytes, int offset, int size)
bytes
- the array to load the file intooffset
- the offset to start writing bytessize
- the number of bytes to read, see length()
public java.io.OutputStream write(boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public void write(java.io.InputStream input, boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public java.io.Writer writer(boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public java.io.Writer writer(boolean append, java.lang.String charset)
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.public void writeString(java.lang.String string, boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public void writeString(java.lang.String string, boolean append, java.lang.String charset)
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.public void writeBytes(byte[] bytes, boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public void writeBytes(byte[] bytes, int offset, int length, boolean append)
append
- If false, this file will be overwritten if it exists, otherwise it will be appended.public FileHandle[] list()
Files.FileType.Internal
handle to a directory on the classpath will return a zero length
array.
public FileHandle[] list(java.lang.String suffix)
Files.FileType.Internal
handle to a directory on the classpath
will return a zero length array.
public boolean isDirectory()
Files.FileType.Internal
handle to an empty directory will return false. On the desktop, an Files.FileType.Internal
handle to a directory on the
classpath will return false.
public FileHandle child(java.lang.String name)
public FileHandle parent()
public void mkdirs()
public boolean exists()
Files.FileType.Classpath
or Files.FileType.Internal
handle to a directory
will always return false.
public boolean delete()
public boolean deleteDirectory()
public void copyTo(FileHandle dest)
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, GdxRuntimeException 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, mkdirs()
is called on the destination and this directory is copied into it recursively.
public void moveTo(FileHandle dest)
public long length()
public long lastModified()
Files.FileType.Classpath
files. On Android, zero is returned for Files.FileType.Internal
files. On the desktop, zero
is returned for Files.FileType.Internal
files on the classpath.
public java.lang.String toString()
toString
in class java.lang.Object
public static FileHandle tempFile(java.lang.String prefix)
public static FileHandle tempDirectory(java.lang.String prefix)
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |