com.golden.gamedev.util
Class FileUtil

java.lang.Object
  |
  +--com.golden.gamedev.util.FileUtil

public class FileUtil
extends Object

Utility class for reading and writing text file, also several methods for processing File object.


Method Summary
static String[] fileRead(File file)
          Read an array of String from specified text file.
static String[] fileRead(InputStream stream)
           
static String[] fileRead(InputStream stream, String ignore, boolean readEmpty)
           
static void fileWrite(String[] text, File file)
          Writes an array of String to specified text file.
static String getExtension(File f)
          Returns the extension of specified file.
static String getExtension(String st)
           
static String getName(File f)
          Returns the name of specified file without it's extension.
static String getName(String st)
           
static String getPath(File f)
          Returns the path of specified file.
static String getPath(String st)
           
static String getPathName(File f)
          Returns the path and the name of specified file without its extension.
static String getPathName(String st)
           
static File setExtension(File f, String ext)
          Sets file extension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

fileWrite

public static void fileWrite(String[] text,
                             File file)
Writes an array of String to specified text file.

Parameters:
text - an array of string to write to the file.
file - file to be written.

fileRead

public static String[] fileRead(File file)
Read an array of String from specified text file. Returns a compact string. Each returned string represent each line in the file.

Parameters:
file - file to be read.
Returns:
An array of string from the file, null if file cannot be read

fileRead

public static String[] fileRead(InputStream stream)

fileRead

public static String[] fileRead(InputStream stream,
                                String ignore,
                                boolean readEmpty)

setExtension

public static File setExtension(File f,
                                String ext)
Sets file extension.
For example renaming "paul.dat" to "paul.bin":
    File f = new File("paul.dat");
    File newFile = setExtension(f, "bin");
 

Parameters:
f - file that it's extension to be renamed.
ext - the new file extension.
Returns:
The file with new extension

getExtension

public static String getExtension(File f)
Returns the extension of specified file. A file with name "paul.dat" will return "dat".

Parameters:
f - file to get it's extension.
Returns:
The file extension

getExtension

public static String getExtension(String st)

getName

public static String getName(File f)
Returns the name of specified file without it's extension. A file with name "paul.dat" will return "paul".

Parameters:
f - file to get it's name.
Returns:
The file name

getName

public static String getName(String st)

getPath

public static String getPath(File f)
Returns the path of specified file. A file with path "c:\src\res\paul.dat" will return "c:\src\res\".

Parameters:
f - file to get it's path.
Returns:
The file path

getPath

public static String getPath(String st)

getPathName

public static String getPathName(File f)
Returns the path and the name of specified file without its extension. A file with path "c:\src\res\paul.dat" will return "c:\src\res\paul".

Parameters:
f - file to get it's pathname.
Returns:
The file pathname

getPathName

public static String getPathName(String st)