GTGE API

com.golden.gamedev.util
Class FileUtil

java.lang.Object
  extended by com.golden.gamedev.util.FileUtil

public class FileUtil
extends Object

Utility class provides functions for processing java.io.File object, such as renaming file extension, reading and writing text file, etc.


Method Summary
static String[] fileRead(File file)
          Read an array of String from specified text file.
static String[] fileRead(InputStream stream)
          Read an array of String from specified stream.
static String[] fileRead(URL url)
          Read an array of String from specified URL.
static boolean fileWrite(String[] text, File file)
          Writes an array of String to specified text file.
static String getExtension(File f)
          Returns extension of a file.
static String getExtension(String st)
          Returns extension of a string.
static String getName(File f)
          Returns name of a file without its extension.
static String getName(String st)
          Returns name of a string without its extension.
static String getPath(File f)
          Returns the path of specified file.
static String getPath(String st)
          Returns path of a string.
static String getPathName(File f)
          Returns path and name of a file without its extension.
static String getPathName(String st)
          Returns path and name of a string without its extension.
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 boolean 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 - a text file to be written the text to
Returns:
true, if the text successfuly write to the file.

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 read from the file, or null if the file cannot be read.

fileRead

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

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

fileRead

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

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

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 extension of a 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)
Returns extension of a string.
A string with "paul.dat" will return "dat".

Parameters:
st - string to get its extension
Returns:
The file extension.

getName

public static String getName(File f)
Returns name of a file without its 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)
Returns name of a string without its extension.
A string "paul.dat" will return "paul".

Parameters:
st - string to get its name
Returns:
The file name.

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 its path
Returns:
The file path.

getPath

public static String getPath(String st)
Returns path of a string.
A string "c:\src\res\paul.dat" will return "c:\src\res\".

Parameters:
st - string to get its path
Returns:
The file path.

getPathName

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

Parameters:
f - file to get its pathname
Returns:
The file pathname.

getPathName

public static String getPathName(String st)
Returns path and name of a string without its extension.
A string "c:\src\res\paul.dat" will return "c:\src\res\paul".

Parameters:
st - string to get its pathname
Returns:
The file pathname.

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id