Package net.sf.robocode.io
Class FileUtil
java.lang.Object
net.sf.robocode.io.FileUtil
This is a class for file utilization.
- Author:
- Mathew A. Nelson (original), Flemming N. Larsen (contributor)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
cleanupStream
(Object stream) Cleans up a stream by flushing it and closing it if it is not null.static void
Copies a file into another file.static File
Creates a directory if it does not exist alreadystatic boolean
Deletes a directory.static File
Returns the directory containing the battle files.static String
getClassName
(String fileName) Returns the class name of the specified filename.static File
Returns the compiler configuration file.static File
Returns the directory containing the configuration files.static File
getCwd()
Returns the current working directory.static File
Returns the source code editor configuration file.static File
Returns the editor theme directory.static String
getFileType
(File file) Returns the file type of a file, i.e.static String
getFileType
(String fileName) Returns the file type of a file name, i.e.static File
Returns the Robocode configuration file.static File
Returns the robot database file.static File
Returns the directory containing data files of robots.static File
Returns the directory containing the robots.static File
Returns the directory containing the screen shot files.static File
Returns the window configuration file.static boolean
isFilenameValid
(String file) Checks if a filename is valid.static String
quoteFileName
(String filename) Quotes a file name if it contains white spaces and has not already been quoted.static void
Changes the current working directory.
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
getCwd
Returns the current working directory.- Returns:
- a File for the current working directory
-
setCwd
Changes the current working directory.- Parameters:
cwd
- a File that is the new working directory- Throws:
IOException
- if an I/O exception occurs
-
getFileType
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
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
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
Copies a file into another file.- Parameters:
srcFile
- the input file to copydestFile
- the output file to copy to- Throws:
IOException
- if an I/O exception occurs
-
deleteDir
Deletes a directory.- Parameters:
dir
- the file for the directory to delete- Returns:
- true if success
-
createDir
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
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
Returns the directory containing the robots.- Returns:
- a File that is the directory containing the robots
-
getRobotDatabaseFile
Returns the robot database file.- Returns:
- a File that is the directory containing the robot cache.
-
getRobotsDataDir
Returns the directory containing data files of robots.- Returns:
- a File that is the directory containing the robot data.
-
getBattlesDir
Returns the directory containing the battle files.- Returns:
- a File that is the directory containing the battle files
-
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
-
getScreenshotsDir
Returns the directory containing the screen shot files. If the directory does not exist, it will be created automatically.- Returns:
- a File that is the directory containing screen shot files
-
getRobocodeConfigFile
Returns the Robocode configuration file.- Returns:
- a File that is the Robocode configuration file.
-
getWindowConfigFile
Returns the window configuration file.- Returns:
- a File that is the window configuration file.
-
getCompilerConfigFile
Returns the compiler configuration file.- Returns:
- a File that is the compiler configuration file.
-
getEditorConfigFile
Returns the source code editor configuration file.- Returns:
- a File that is the editor configuration file.
-
getEditorThemeConfigDir
Returns the editor theme directory.- Returns:
- a File that is the directory containing the editor theme files.
-
cleanupStream
Cleans up a stream by flushing it and closing it if it is not null.- Parameters:
stream
- the stream to clean up.
-
isFilenameValid
Checks if a filename is valid.- Parameters:
file
- the filename to check.- Returns:
- true if the filename is valid; false otherwise.
-