Class FileSystem


  • public class FileSystem
    extends java.lang.Object
    Some static methods to handle the filesystem.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileSystem()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean exists​(java.lang.String ElementPath)
      Returns true if in the given path exists an element, false otherwise.
      static java.lang.String extractFileExtension​(java.lang.String FilePath)
      This method extracts the extension from the given filename.
      static java.lang.String getJARDirectoryPath()
      This method returns a string with the jar directory path of this program.
      static java.lang.String getJARDirectoryPath​(java.lang.Class<?> ClassRelative)
      This method returns a string with the jar directory path of this program.
      static java.lang.String getJARPath()
      This method returns a string with the jar path of this program.
      static java.lang.String getJARPath​(java.lang.Class<?> ClassRelative)
      This method returns a string with the jar path of this program.
      static java.io.InputStream getResource​(java.lang.String Name)
      Returns an InputStream of the resource specified in Name.
      static java.io.InputStream getResource​(java.lang.String Name, java.lang.Class<?> ClassRelative)
      Returns an InputStream of the resource specified in Name.
      static boolean isDirectory​(java.lang.String ElementPath)
      Like the name implies, this method returns true if the element is a directory.
      static boolean isFile​(java.lang.String ElementPath)
      Like the name implies, this method returns true if the element is a file.
      static java.util.Properties loadConfig​(java.lang.String LoadPath)
      Loads a configuration file located in the specified path.
      static void makeDirectoryIfNotExists​(java.lang.String DirPath)
      This method creates a directory if the directory doesn't exists.
      static void makeDirectoryIfNotExists​(java.lang.String[] DirPaths)
      This method creates directories if the directories doesn't exists.
      static boolean resourceExists​(java.lang.String Name)
      Checks if the given resource name exists in path.
      static boolean resourceExists​(java.lang.String Name, java.lang.Class<?> ClassRelative)
      Checks if the given resource name exists in path.
      static void saveConfig​(java.util.Properties Config, java.lang.String SavePath)
      Saves a Properties object to a file specified in the SavePath parameter.
      static void saveConfig​(java.util.Properties Config, java.lang.String SavePath, java.lang.String Comment)
      Saves a Properties object to a file specified in the SavePath parameter.
      static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan)
      Scans the given directory and returns a File array with all the files and directories found in.
      static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan, boolean RecursiveScan)
      Scans the given directory and returns a File array with all the files and directories found in.
      static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan, boolean RecursiveScan, int Levels)
      Scans the given directory and returns a File array with all the files and directories found in.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileSystem

        public FileSystem()
    • Method Detail

      • getJARDirectoryPath

        public static java.lang.String getJARDirectoryPath​(java.lang.Class<?> ClassRelative)
        This method returns a string with the jar directory path of this program.
        Parameters:
        ClassRelative - Class from which to get the jar directory path.
        Returns:
        String containing the program's jar directory path.
        Since:
        1.0.0
        See Also:
        getJARPath(java.lang.Class<?>)
      • getJARDirectoryPath

        public static java.lang.String getJARDirectoryPath()
        This method returns a string with the jar directory path of this program.
        Returns:
        String containing the program's jar directory path.
        Since:
        1.4.0
        See Also:
        getJARPath(java.lang.Class<?>)
      • getJARPath

        public static java.lang.String getJARPath​(java.lang.Class<?> ClassRelative)
        This method returns a string with the jar path of this program.
        Parameters:
        ClassRelative - Class from which to get the jar file path.
        Returns:
        String containing the program's jar path.
        Since:
        1.1.0
        See Also:
        getJARDirectoryPath(java.lang.Class<?>)
      • getJARPath

        public static java.lang.String getJARPath()
        This method returns a string with the jar path of this program.
        Returns:
        String containing the program's jar path.
        Since:
        1.4.0
        See Also:
        getJARDirectoryPath(java.lang.Class<?>)
      • loadConfig

        public static java.util.Properties loadConfig​(java.lang.String LoadPath)
                                               throws java.io.FileNotFoundException,
                                                      java.io.IOException
        Loads a configuration file located in the specified path.
        Parameters:
        LoadPath - String containing the path where the file is located.
        Returns:
        Properties object containing the configuration loaded from the file.
        Throws:
        java.io.FileNotFoundException - Throwed when the file doesn't exists.
        java.io.IOException - Throwed when there is an in/out error.
        Since:
        1.1.0
        See Also:
        saveConfig(java.util.Properties,java.lang.String,java.lang.String)
      • saveConfig

        public static void saveConfig​(java.util.Properties Config,
                                      java.lang.String SavePath,
                                      java.lang.String Comment)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        Saves a Properties object to a file specified in the SavePath parameter.
        Parameters:
        Config - Properties object containing the configuration to be saved.
        SavePath - String containing the path of the config file.
        Comment - String containing a comment for the config file.
        Throws:
        java.io.FileNotFoundException - Throwed when the supplied file path is not valid.
        java.io.IOException - Throwed when there is an in/out error.
        Since:
        1.1.0
        See Also:
        loadConfig(java.lang.String)
      • saveConfig

        public static void saveConfig​(java.util.Properties Config,
                                      java.lang.String SavePath)
                               throws java.io.FileNotFoundException,
                                      java.io.IOException
        Saves a Properties object to a file specified in the SavePath parameter.
        Parameters:
        Config - Properties object containing the configuration to be saved.
        SavePath - String containing the path of the config file.
        Throws:
        java.io.FileNotFoundException - Throwed when the supplied file path is not valid.
        java.io.IOException - Throwed when there is an in/out error.
        Since:
        1.1.0
        See Also:
        loadConfig(java.lang.String)
      • exists

        public static boolean exists​(java.lang.String ElementPath)
        Returns true if in the given path exists an element, false otherwise.
        Parameters:
        ElementPath - String containing the path of the element.
        Returns:
        Boolean true value if the element exists, false otherwise.
        Since:
        1.1.0
        See Also:
        isFile(java.lang.String), isDirectory(java.lang.String)
      • isFile

        public static boolean isFile​(java.lang.String ElementPath)
        Like the name implies, this method returns true if the element is a file.
        Parameters:
        ElementPath - String containing the path of the element.
        Returns:
        Boolean true if is a file, false otherwise.
        Since:
        1.1.0
        See Also:
        isDirectory(java.lang.String)
      • isDirectory

        public static boolean isDirectory​(java.lang.String ElementPath)
        Like the name implies, this method returns true if the element is a directory.
        Parameters:
        ElementPath - String containing the path of the element.
        Returns:
        Boolean true if is a directory, false otherwise.
        Since:
        1.1.0
        See Also:
        isFile(java.lang.String)
      • scanDirectory

        public static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan,
                                                   boolean RecursiveScan,
                                                   int Levels)
                                            throws java.io.FileNotFoundException,
                                                   java.io.IOException
        Scans the given directory and returns a File array with all the files and directories found in.
        Parameters:
        DirectoryToScan - String containing the path of the directory.
        RecursiveScan - Boolean value indicating a recursive scan.
        Levels - Integer containing the level of recursion, if this is -2, it recurses infinitely.
        Returns:
        File array with all of the files and directories inside the directory.
        Throws:
        java.io.FileNotFoundException - Throwed when the directory doesn't exists.
        java.io.IOException - Throwed when the given path is not a directory.
        Since:
        1.1.0
      • scanDirectory

        public static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan)
                                            throws java.io.FileNotFoundException,
                                                   java.io.IOException
        Scans the given directory and returns a File array with all the files and directories found in. This method doesn't scan recursively.
        Parameters:
        DirectoryToScan - String containing the path of the directory.
        Returns:
        File array with all of the files and directories inside the directory.
        Throws:
        java.io.FileNotFoundException - Throwed when the directory doesn't exists.
        java.io.IOException - Throwed when the given path is not a directory.
        Since:
        1.1.0
      • scanDirectory

        public static java.io.File[] scanDirectory​(java.lang.String DirectoryToScan,
                                                   boolean RecursiveScan)
                                            throws java.io.FileNotFoundException,
                                                   java.io.IOException
        Scans the given directory and returns a File array with all the files and directories found in. This method has infinite recursion if the RecursiveScan parameter is true.
        Parameters:
        DirectoryToScan - String containing the path of the directory.
        RecursiveScan - Boolean value indicating a recursive scan.
        Returns:
        File array with all of the files and directories inside the directory.
        Throws:
        java.io.FileNotFoundException - Throwed when the directory doesn't exists.
        java.io.IOException - Throwed when the given path is not a directory.
        Since:
        1.2.0
      • resourceExists

        public static boolean resourceExists​(java.lang.String Name,
                                             java.lang.Class<?> ClassRelative)
        Checks if the given resource name exists in path.
        Parameters:
        Name - String containing the path of the resource.
        ClassRelative - Class used to set the relative path of the resource to check.
        Returns:
        Boolean true if exists, false otherwise.
        Since:
        1.2.0
      • resourceExists

        public static boolean resourceExists​(java.lang.String Name)
        Checks if the given resource name exists in path.
        Parameters:
        Name - String containing the path of the resource.
        Returns:
        Boolean true if exists, false otherwise.
        Since:
        1.4.0
      • getResource

        public static java.io.InputStream getResource​(java.lang.String Name,
                                                      java.lang.Class<?> ClassRelative)
                                               throws java.io.FileNotFoundException
        Returns an InputStream of the resource specified in Name.
        Parameters:
        Name - String containing the path to the resource.
        ClassRelative - Class used to set the relative path of the resource.
        Returns:
        InputStream of the resource.
        Throws:
        java.io.FileNotFoundException - Throwed when the given resource doesn't exists.
        Since:
        1.2.0
      • getResource

        public static java.io.InputStream getResource​(java.lang.String Name)
                                               throws java.io.FileNotFoundException
        Returns an InputStream of the resource specified in Name.
        Parameters:
        Name - String containing the path to the resource.
        Returns:
        InputStream of the resource.
        Throws:
        java.io.FileNotFoundException - Throwed when the given resource doesn't exists.
        Since:
        1.4.0
      • extractFileExtension

        public static java.lang.String extractFileExtension​(java.lang.String FilePath)
        This method extracts the extension from the given filename.
        Parameters:
        FilePath - String containing the filename path.
        Returns:
        String containing the extension, if the given name has no extension, it will return null.
        Since:
        1.3.0
      • makeDirectoryIfNotExists

        public static void makeDirectoryIfNotExists​(java.lang.String DirPath)
                                             throws java.io.IOException
        This method creates a directory if the directory doesn't exists.
        Parameters:
        DirPath - String containing the path of the directory.
        Throws:
        java.io.IOException - Throwed when there is a in/out error.
        Since:
        1.3.0
      • makeDirectoryIfNotExists

        public static void makeDirectoryIfNotExists​(java.lang.String[] DirPaths)
                                             throws java.io.IOException
        This method creates directories if the directories doesn't exists.
        Parameters:
        DirPaths - String array containing the path of the directories.
        Throws:
        java.io.IOException - Throwed when there is a in/out error.
        Since:
        1.3.0