libgdx API

com.badlogic.gdx.files
Class FileHandle

java.lang.Object
  extended by com.badlogic.gdx.files.FileHandle
Direct Known Subclasses:
FileHandleStream

public class FileHandle
extends java.lang.Object

Represents a file or directory on the filesystem, classpath, Android SD card, or Android assets directory. FileHandles are created via a Files instance.

Author:
mzechner, Nathan Sweet

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 to the specified file, overwriting the file if it already exists.
 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()
           
 boolean isDirectory()
          Returns true if this file is a directory.
 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.
 byte[] readBytes()
          Reads the entire file into a byte array.
 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.
 java.lang.String toString()
           
 Files.FileType type()
           
 java.io.OutputStream write(boolean append)
          Returns a stream for writing to this file.
 java.io.Writer writer(boolean append)
          Returns a writer for writing to this file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

file

protected java.io.File file

type

protected Files.FileType type
Constructor Detail

FileHandle

protected FileHandle()

FileHandle

public FileHandle(java.lang.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 Files interface instead.

Parameters:
fileName - the filename.

FileHandle

public FileHandle(java.io.File file)
Creates a new absolute FileHandle for the 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.

Parameters:
file - the file.

FileHandle

protected FileHandle(java.lang.String fileName,
                     Files.FileType type)

FileHandle

protected FileHandle(java.io.File file,
                     Files.FileType type)
Method Detail

path

public java.lang.String path()

name

public java.lang.String name()

extension

public java.lang.String extension()

nameWithoutExtension

public java.lang.String nameWithoutExtension()

type

public Files.FileType type()

read

public java.io.InputStream read()
Returns a stream for reading this file.


readString

public java.lang.String readString()
Reads the entire file into a string using the platform's default charset.


readString

public java.lang.String readString(java.lang.String charset)
Reads the entire file into a string using the specified charset.


readBytes

public byte[] readBytes()
Reads the entire file into a byte array.


write

public java.io.OutputStream write(boolean append)
Returns a stream for writing to this file.

Parameters:
append - If false, this file will be overwritten if it exists, otherwise it will be appended.

writer

public java.io.Writer writer(boolean append)
Returns a writer for writing to this file.

Parameters:
append - If false, this file will be overwritten if it exists, otherwise it will be appended.

list

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 internal handle to a directory on the classpath will return a zero length array.


list

public FileHandle[] list(java.lang.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 internal handle to a directory on the classpath will return a zero length array.


isDirectory

public boolean isDirectory()
Returns true if this file is a directory. Always returns false for classpath files. On Android, an internal handle to an empty directory will return false. On the desktop, an internal handle to a directory on the classpath will return false.


child

public FileHandle child(java.lang.String name)
Returns a handle to the child with the specified name.


parent

public FileHandle parent()

mkdirs

public void mkdirs()

exists

public boolean exists()
Returns true if the file exists. On Android, a classpath handle to a directory will always return false.


delete

public boolean delete()
Deletes this file or empty directory and returns success. Will not delete a directory that has children.


deleteDirectory

public boolean deleteDirectory()
Deletes this file or directory and all children, recursively.


copyTo

public void copyTo(FileHandle dest)
Copies this file to the specified file, overwriting the file if it already exists.


moveTo

public void moveTo(FileHandle dest)
Moves this file to the specified file, overwriting the file if it already exists.


length

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.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)