Module de.carne

Class FileUtil


  • public final class FileUtil
    extends java.lang.Object
    Utility class providing file related functions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean delete​(java.nio.file.Path fileOrDirectory)
      Deletes a file or directory (including any included file).
      static @NonNull java.lang.String[] splitPath​(java.lang.String path)
      Splits a path into it's three parts directory, name and extension.
      static java.nio.file.Path tmpDir()
      Gets the temporary directory path.
      static java.nio.file.Path touch​(java.nio.file.Path file)
      Sets the submitted file last modified time to the current time.
      static java.nio.file.Path userHomeDir()
      Gets the user's home directory path.
      static java.nio.file.Path workingDir()
      Gets the current working directory path.
      • Methods inherited from class java.lang.Object

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

      • tmpDir

        public static java.nio.file.Path tmpDir()
        Gets the temporary directory path.
        Returns:
        the temporary directory path.
      • userHomeDir

        public static java.nio.file.Path userHomeDir()
        Gets the user's home directory path.
        Returns:
        the user's home directory path.
      • workingDir

        public static java.nio.file.Path workingDir()
        Gets the current working directory path.
        Returns:
        the current working directory path.
      • touch

        public static java.nio.file.Path touch​(java.nio.file.Path file)
                                        throws java.io.IOException
        Sets the submitted file last modified time to the current time.

        If the file does not yet exist, it will be created.

        Parameters:
        file - the file to touch.
        Returns:
        the submitted file.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • delete

        public static boolean delete​(java.nio.file.Path fileOrDirectory)
                              throws java.io.IOException
        Deletes a file or directory (including any included file).
        Parameters:
        fileOrDirectory - the file or director to delete.
        Returns:
        true if the file or directory was deleted. false if the file or directory does not exist.
        Throws:
        java.io.IOException - if an I/O error occurs during deletion.
      • splitPath

        public static @NonNull java.lang.String[] splitPath​(java.lang.String path)
        Splits a path into it's three parts directory, name and extension.

        For missing parts the empty string is returned.

        Parameters:
        path - the path to split.
        Returns:
        the three path parts.