Files instance.
Because some of the file types are backed by composite files and may be compressed (for example, if they are in an Android .apk
or are found via the classpath), the methods for extracting a path() or file() may not be appropriate for all
types. Use the Reader or Stream methods here to hide these dependencies from your platform independent code.
| Access | Constructor and Description |
|---|---|
| protected | |
| public | |
| public | |
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public FileHandle | |
| private static void | |
| private static void | |
| public void | |
| public boolean | |
| public boolean | |
| private static boolean | |
| public void | |
| public void | |
| private static void | |
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| private int | |
| public boolean | |
| public String | extension()
Returns the file extension (without the dot) or an empty string if the file name doesn't contain a dot. |
| public File | |
| public int | |
| public boolean | |
| public long | |
| public 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. |
| public FileHandle[] | |
| public FileHandle[] | list(FileFilter
the filter)FileFilter to filter filesReturns the paths to the children of this directory that satisfy the specified filter. |
| public FileHandle[] | list(FilenameFilter
the filter)FilenameFilter to filter filesReturns the paths to the children of this directory that satisfy the specified filter. |
| public FileHandle[] | |
| public ByteBuffer | |
| public ByteBuffer | |
| public void | |
| public void | moveTo(FileHandle dest)
Moves this file to the specified file, overwriting the file if it already exists. |
| public String | |
| public String | |
| public FileHandle | |
| public String | path()
Returns: the path of the file as specified on construction, e.g. Gdx.files.internal("dir/file.png") -> dir/file.png. |
| public String | pathWithoutExtension()
Returns: the path and filename without the extension, e.g. dir/dir2/file.png -> dir/dir2/file. |
| public InputStream | |
| public BufferedInputStream | |
| public byte[] | |
| public int | |
| public Reader | |
| public Reader | |
| public BufferedReader | reader(int bufferSize)
Returns a buffered reader for reading this file as characters using the platform's default charset. |
| public BufferedReader | |
| public String | |
| public String | readString(String
If null the default charset is used. charset)Reads the entire file into a string using the specified charset. |
| public FileHandle | |
| public static FileHandle | |
| public static FileHandle | |
| public String | |
| public Files. | |
| public OutputStream | write(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Returns a stream for writing to this file. |
| public OutputStream | write(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append, int The size of the buffer. bufferSize)Returns a buffered stream for writing to this file. |
| public void | write(InputStream input, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Reads the remaining bytes from the specified stream and writes them to this file. |
| public void | writeBytes(byte[] bytes, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Writes the specified bytes to the file. |
| public void | writeBytes(byte[] bytes, int offset, int length, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Writes the specified bytes to the file. |
| public Writer | writer(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Returns a writer for writing to this file using the default charset. |
| public Writer | |
| public void | writeString(String string, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append)Writes the specified string to the file using the default charset. |
| public void | writeString(String string, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended. append, String May be null to use the default charset. charset)Writes the specified string to the file using the specified charset. |
| file | back to summary |
|---|---|
| protected File file | |
| type | back to summary |
|---|---|
| protected Files. | |
| FileHandle | back to summary |
|---|---|
| protected FileHandle() | |
| FileHandle | back to summary |
|---|---|
| public FileHandle(String fileName) Creates a new absolute FileHandle for the file name. 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
| |
| FileHandle | back to summary |
|---|---|
| public FileHandle(File file) Creates a new absolute FileHandle for the
| |
| FileHandle | back to summary |
|---|---|
| protected FileHandle(String fileName, Files. | |
| FileHandle | back to summary |
|---|---|
| protected FileHandle(File file, Files. | |
| child | back to summary |
|---|---|
| public FileHandle child(String name) Returns a handle to the child with the specified name. | |
| copyDirectory | back to summary |
|---|---|
| private static void copyDirectory(FileHandle sourceDir, FileHandle destDir) | |
| copyFile | back to summary |
|---|---|
| private static void copyFile(FileHandle source, FileHandle dest) | |
| copyTo | back to summary |
|---|---|
| public void copyTo(FileHandle dest) Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a
file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination
doesn't exist,
| |
| delete | back to summary |
|---|---|
| public boolean delete() Deletes this file or empty directory and returns success. Will not delete a directory that has children.
| |
| deleteDirectory | back to summary |
|---|---|
| public boolean deleteDirectory() Deletes this file or directory and all children, recursively.
| |
| deleteDirectory | back to summary |
|---|---|
| private static boolean deleteDirectory(File file) | |
| emptyDirectory | back to summary |
|---|---|
| public void emptyDirectory() Deletes all children of this directory, recursively.
| |
| emptyDirectory | back to summary |
|---|---|
| public void emptyDirectory(boolean preserveTree) Deletes all children of this directory, recursively. Optionally preserving the folder structure.
| |
| emptyDirectory | back to summary |
|---|---|
| private static void emptyDirectory(File file, boolean preserveTree) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| estimateLength | back to summary |
|---|---|
| private int estimateLength() | |
| exists | back to summary |
|---|---|
| public boolean exists() Returns true if the file exists. On Android, a | |
| extension | back to summary |
|---|---|
| public String extension() Returns the file extension (without the dot) or an empty string if the file name doesn't contain a dot. | |
| file | back to summary |
|---|---|
| public File file() Returns a java.io.File that represents this file handle. Note the returned file will only be usable for
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isDirectory | back to summary |
|---|---|
| public boolean isDirectory() Returns true if this file is a directory. Always returns false for classpath files. On Android, an
| |
| lastModified | back to summary |
|---|---|
| public long lastModified() Returns the last modified time in milliseconds for this file. Zero is returned if the file doesn't exist. Zero is returned
for | |
| length | back to summary |
|---|---|
| public 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. | |
| list | back to summary |
|---|---|
| public FileHandle[] list() Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a
directory. On the desktop, an
| |
| list | back to summary |
|---|---|
| public FileHandle[] list(FileFilter filter) Returns the paths to the children of this directory that satisfy the specified filter. Returns an empty list if this file
handle represents a file and not a directory. On the desktop, an
| |
| list | back to summary |
|---|---|
| public FileHandle[] list(FilenameFilter filter) Returns the paths to the children of this directory that satisfy the specified filter. Returns an empty list if this file
handle represents a file and not a directory. On the desktop, an
| |
| list | back to summary |
|---|---|
| public FileHandle[] list(String suffix) Returns the paths to the children of this directory with the specified suffix. Returns an empty list if this file handle
represents a file and not a directory. On the desktop, an
| |
| map | back to summary |
|---|---|
| public ByteBuffer map() Attempts to memory map this file in READ_ONLY mode. Android files must not be compressed.
| |
| map | back to summary |
|---|---|
| public ByteBuffer map(FileChannel. Attempts to memory map this file. Android files must not be compressed.
| |
| mkdirs | back to summary |
|---|---|
public void mkdirs()
| |
| moveTo | back to summary |
|---|---|
| public void moveTo(FileHandle dest) Moves this file to the specified file, overwriting the file if it already exists.
| |
| name | back to summary |
|---|---|
public String name()
| |
| nameWithoutExtension | back to summary |
|---|---|
public String nameWithoutExtension()
| |
| parent | back to summary |
|---|---|
| public FileHandle parent() | |
| path | back to summary |
|---|---|
public String path()
| |
| pathWithoutExtension | back to summary |
|---|---|
public String pathWithoutExtension()
| |
| read | back to summary |
|---|---|
| public InputStream read() Returns a stream for reading this file as bytes.
| |
| read | back to summary |
|---|---|
| public BufferedInputStream read(int bufferSize) Returns a buffered stream for reading this file as bytes.
| |
| readBytes | back to summary |
|---|---|
| public byte[] readBytes() Reads the entire file into a byte array.
| |
| readBytes | back to summary |
|---|---|
| public int readBytes(byte[] bytes, int offset, int size) Reads the entire file into the byte array. The byte array must be big enough to hold the file's data.
| |
| reader | back to summary |
|---|---|
| public Reader reader() Returns a reader for reading this file as characters the platform's default charset.
| |
| reader | back to summary |
|---|---|
| public Reader reader(String charset) Returns a reader for reading this file as characters.
| |
| reader | back to summary |
|---|---|
| public BufferedReader reader(int bufferSize) Returns a buffered reader for reading this file as characters using the platform's default charset.
| |
| reader | back to summary |
|---|---|
| public BufferedReader reader(int bufferSize, String charset) Returns a buffered reader for reading this file as characters.
| |
| readString | back to summary |
|---|---|
| public String readString() Reads the entire file into a string using the platform's default charset.
| |
| readString | back to summary |
|---|---|
| public String readString(String charset) Reads the entire file into a string using the specified charset.
| |
| sibling | back to summary |
|---|---|
| public FileHandle sibling(String name) Returns a handle to the sibling with the specified name.
| |
| tempDirectory | back to summary |
|---|---|
| public static FileHandle tempDirectory(String prefix) | |
| tempFile | back to summary |
|---|---|
| public static FileHandle tempFile(String prefix) | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| type | back to summary |
|---|---|
| public Files. | |
| write | back to summary |
|---|---|
| public OutputStream write(boolean append) Returns a stream for writing to this file. Parent directories will be created if necessary.
| |
| write | back to summary |
|---|---|
| public OutputStream write(boolean append, int bufferSize) Returns a buffered stream for writing to this file. Parent directories will be created if necessary.
| |
| write | back to summary |
|---|---|
| public void write(InputStream input, boolean append) Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed. Parent directories will be created if necessary.
| |
| writeBytes | back to summary |
|---|---|
| public void writeBytes(byte[] bytes, boolean append) Writes the specified bytes to the file. Parent directories will be created if necessary.
| |
| writeBytes | back to summary |
|---|---|
| public void writeBytes(byte[] bytes, int offset, int length, boolean append) Writes the specified bytes to the file. Parent directories will be created if necessary.
| |
| writer | back to summary |
|---|---|
| public Writer writer(boolean append) Returns a writer for writing to this file using the default charset. Parent directories will be created if necessary.
| |
| writer | back to summary |
|---|---|
| public Writer writer(boolean append, String charset) Returns a writer for writing to this file. Parent directories will be created if necessary.
| |
| writeString | back to summary |
|---|---|
| public void writeString(String string, boolean append) Writes the specified string to the file using the default charset. Parent directories will be created if necessary.
| |
| writeString | back to summary |
|---|---|
| public void writeString(String string, boolean append, String charset) Writes the specified string to the file using the specified charset. Parent directories will be created if necessary.
| |