Class FileUtils


  • public class FileUtils
    extends Object

    Utility class for files

    Since:
    2.0
    Author:
    Christoph Praschl
    • Method Detail

      • toCompliantPath

        public static String toCompliantPath​(String path)
        Help method which creates a compliant path string using File.separator, which is required by the methods of FileUtils
        Parameters:
        path - path which contains slash "/" as file separator
        Returns:
        compliant path string
      • createTempDirectory

        public static Path createTempDirectory​(String directoryHierarchy)
        Method which creates a directory in the temp folder based on the given directoryHierarchy (subfolder separated by File.separator)
        Parameters:
        directoryHierarchy - defining the sub folders' name
        Returns:
        path to the temp directory
      • createTempFile

        public static Path createTempFile​(String fileName,
                                          String fileExtension)
        Creates a file in the temp folder
        Parameters:
        fileName - name of the file which should be created
        fileExtension - file extension of the file which should be created
        Returns:
        the created file
      • createTempFile

        public static Path createTempFile​(String dirPath,
                                          String fileName,
                                          String fileExtension)
        Creates a file in a subfolder (respectively directory hierarchy) of the temp folder
        Parameters:
        dirPath - the path of the subfolder
        fileName - name of the file which should be created
        fileExtension - file extension of the file which should be created
        Returns:
        the created file
      • writeToTempFile

        public static File writeToTempFile​(String fileName,
                                           String fileExtension,
                                           InputStream is)
        Writes the given inputStream to a file (given by the file name and file extension) in the local TEMP directory
        Parameters:
        fileName - name of the file which should be created
        fileExtension - file extension of the file which should be created
        is - InputStream which should be written to a new file in the TEMP directory (is not closed inside of this method!); if null nothing is written to the created file
        Returns:
        the created file
      • writeToTempFile

        public static File writeToTempFile​(String dirPath,
                                           String fileName,
                                           String fileExtension,
                                           InputStream is)
        Writes the given inputStream to a file (given by the file name and file extension) into a subfolder of the local TEMP directory
        Parameters:
        dirPath - Path of the subfolder in the local TEMP directory (may be null; if not use File.separator for separating different subfolders!)
        fileName - name of the file which should be created
        fileExtension - file extension of the file which should be created
        is - InputStream which should be written to a new file in the TEMP directory (is not closed inside of this method!); if null nothing is written to the created file
        Returns:
        the created file