Class FileUtil

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

public class FileUtil extends Object
This is a class for file utilization.
Author:
Mathew A. Nelson (original), Flemming N. Larsen (contributor)
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • getCwd

      public static File getCwd()
      Returns the current working directory.
      Returns:
      a File for the current working directory
    • setCwd

      public static void setCwd(File cwd) throws IOException
      Changes the current working directory.
      Parameters:
      cwd - a File that is the new working directory
      Throws:
      IOException - if an I/O exception occurs
    • getFileType

      public static String getFileType(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 String getFileType(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 String quoteFileName(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(File srcFile, File destFile) throws IOException
      Copies a file into another file.
      Parameters:
      srcFile - the input file to copy
      destFile - the output file to copy to
      Throws:
      IOException - if an I/O exception occurs
    • deleteDir

      public static boolean deleteDir(File dir)
      Deletes a directory.
      Parameters:
      dir - the file for the directory to delete
      Returns:
      true if success
    • createDir

      public static File createDir(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 String getClassName(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 File getRobotsDir()
      Returns the directory containing the robots.
      Returns:
      a File that is the directory containing the robots
    • getRobotDatabaseFile

      public static File getRobotDatabaseFile()
      Returns the robot database file.
      Returns:
      a File that is the directory containing the robot cache.
    • getRobotsDataDir

      public static File getRobotsDataDir()
      Returns the directory containing data files of robots.
      Returns:
      a File that is the directory containing the robot data.
    • getBattlesDir

      public static File getBattlesDir()
      Returns the directory containing the battle files.
      Returns:
      a File that is the directory containing the battle files
    • getConfigDir

      public static 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
    • getScreenshotsDir

      public static File 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

      public static File getRobocodeConfigFile()
      Returns the Robocode configuration file.
      Returns:
      a File that is the Robocode configuration file.
    • getWindowConfigFile

      public static File getWindowConfigFile()
      Returns the window configuration file.
      Returns:
      a File that is the window configuration file.
    • getCompilerConfigFile

      public static File getCompilerConfigFile()
      Returns the compiler configuration file.
      Returns:
      a File that is the compiler configuration file.
    • getEditorConfigFile

      public static File getEditorConfigFile()
      Returns the source code editor configuration file.
      Returns:
      a File that is the editor configuration file.
    • getEditorThemeConfigDir

      public static File getEditorThemeConfigDir()
      Returns the editor theme directory.
      Returns:
      a File that is the directory containing the editor theme files.
    • cleanupStream

      public static void cleanupStream(Object stream)
      Cleans up a stream by flushing it and closing it if it is not null.
      Parameters:
      stream - the stream to clean up.
    • isFilenameValid

      public static boolean isFilenameValid(String file)
      Checks if a filename is valid.
      Parameters:
      file - the filename to check.
      Returns:
      true if the filename is valid; false otherwise.