net.sf.robocode.io
Class FileUtil

java.lang.Object
  extended by net.sf.robocode.io.FileUtil

public class FileUtil
extends java.lang.Object

This is a class for file utilization.


Constructor Summary
FileUtil()
           
 
Method Summary
static void cleanupStream(java.lang.Object stream)
          Cleans up a stream by flushing it and closing it if it is not null.
static void copy(java.io.File srcFile, java.io.File destFile)
          Copies a file into another file.
static java.io.File createDir(java.io.File dir)
          Creates a directory if it does not exist already
static boolean deleteDir(java.io.File dir)
          Deletes a directory.
static java.io.File getBattlesDir()
          Returns the directory containing the battle files.
static java.lang.String getClassName(java.lang.String fileName)
          Returns the class name of the specified filename.
static java.io.File getCompilerConfigFile()
          Returns the compiler configuration file.
static java.io.File getConfigDir()
          Returns the directory containing the configuration files.
static java.io.File getCwd()
          Returns the current working directory.
static java.lang.String getFileType(java.io.File file)
          Returns the file type of a file, i.e.
static java.lang.String getFileType(java.lang.String fileName)
          Returns the file type of a file name, i.e.
static java.io.File getRobocodeConfigFile()
          Returns the Robocode configuration file.
static java.io.File getRobotCacheDir()
          Returns the directory containing caches files of robots.
static java.io.File getRobotDatabaseFile()
          Returns the robot database file.
static java.io.File getRobotsDir()
          Returns the directory containing the robots.
static java.io.File getWindowConfigFile()
          Returns the window configuration file.
static java.lang.String quoteFileName(java.lang.String filename)
          Quotes a file name if it contains white spaces and has not already been quoted.
static void setCwd(java.io.File cwd)
          Changes the current working directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

getCwd

public static java.io.File getCwd()
Returns the current working directory.

Returns:
a File for the current working directory

setCwd

public static void setCwd(java.io.File cwd)
                   throws java.io.IOException
Changes the current working directory.

Parameters:
cwd - a File that is the new working directory
Throws:
java.io.IOException - if an I/O exception occurs

getFileType

public static java.lang.String getFileType(java.io.File file)
Returns the file type of a file, i.e. it's extension.

Parameters:
file - the file
Returns:
the file type of the file, e.g. ".class", ".jar" or "" if the file name does not contain an extension.

getFileType

public static java.lang.String getFileType(java.lang.String fileName)
Returns the file type of a file name, i.e. it's extension.

Parameters:
fileName - the file name
Returns:
the file type of the file name, e.g. ".class", ".jar" or "" if the file name does not contain an extension.

quoteFileName

public static java.lang.String quoteFileName(java.lang.String filename)
Quotes a file name if it contains white spaces and has not already been quoted.

Parameters:
filename - the file to quote
Returns:
a quoted version of the specified filename

copy

public static void copy(java.io.File srcFile,
                        java.io.File destFile)
                 throws java.io.IOException
Copies a file into another file.

Parameters:
srcFile - the input file to copy
destFile - the output file to copy to
Throws:
java.io.IOException - if an I/O exception occurs

deleteDir

public static boolean deleteDir(java.io.File dir)
Deletes a directory.

Parameters:
dir - the file for the directory to delete
Returns:
true if susscess

createDir

public static java.io.File createDir(java.io.File dir)
Creates a directory if it does not exist already

Parameters:
dir - the File that represents the new directory to create.
Returns:
the created directory

getClassName

public static java.lang.String getClassName(java.lang.String fileName)
Returns the class name of the specified filename.

Parameters:
fileName - the filename to extract the class name from
Returns:
the class name of the specified filename

getRobotsDir

public static java.io.File getRobotsDir()
Returns the directory containing the robots.

Returns:
a File that is the directory containing the robots

getRobotDatabaseFile

public static java.io.File getRobotDatabaseFile()
Returns the robot database file.

Returns:
a File that is the directory containing the robot cache.

getRobotCacheDir

public static java.io.File getRobotCacheDir()
Returns the directory containing caches files of robots.

Returns:
a File that is the directory containing the robot cache.

getBattlesDir

public static java.io.File getBattlesDir()
Returns the directory containing the battle files.

Returns:
a File that is the directory containing the battle files

getConfigDir

public static java.io.File getConfigDir()
Returns the directory containing the configuration files. If the directory does not exist, it will be created automatically.

Returns:
a File that is the directory containing configuration files

getRobocodeConfigFile

public static java.io.File getRobocodeConfigFile()
Returns the Robocode configuration file.

Returns:
a File that is the Robocode configuration file.

getWindowConfigFile

public static java.io.File getWindowConfigFile()
Returns the window configuration file.

Returns:
a File that the window configuration file.

getCompilerConfigFile

public static java.io.File getCompilerConfigFile()
Returns the compiler configuration file.

Returns:
a File that the compiler configuration file.

cleanupStream

public static void cleanupStream(java.lang.Object stream)
Cleans up a stream by flushing it and closing it if it is not null.

Parameters:
stream - the stream to clean up.