Class FileUtils

java.lang.Object
org.apache.juneau.internal.FileUtils

public class FileUtils extends Object
File utilities.
See Also:
  • Constructor Details

  • Method Details

    • mkdirs

      public static File mkdirs(File f, boolean clean)
      Same as File.mkdirs() except throws a RuntimeExeption if directory could not be created.
      Parameters:
      f - The directory to create. Must not be null.
      clean - If true, deletes the contents of the directory if it already exists.
      Returns:
      The same file.
      Throws:
      RuntimeException - if directory could not be created.
    • mkdirs

      public static File mkdirs(String path, boolean clean)
      Same as mkdirs(String, boolean) but uses String path.
      Parameters:
      path - The path of the directory to create. Must not be null
      clean - If true, deletes the contents of the directory if it already exists.
      Returns:
      The directory.
    • delete

      public static boolean delete(File f)
      Recursively deletes a file or directory.
      Parameters:
      f - The file or directory to delete.
      Returns:
      true if file or directory was successfully deleted.
    • create

      public static void create(File f)
      Creates a file if it doesn't already exist using File.createNewFile().

      Throws a RuntimeException if the file could not be created.

      Parameters:
      f - The file to create.
    • modifyTimestamp

      public static void modifyTimestamp(File f)
      Updates the modified timestamp on the specified file.

      Method ensures that the timestamp changes even if it's been modified within the past millisecond.

      Parameters:
      f - The file to modify the modified timestamp on.
    • createTempFile

      public static File createTempFile(String name) throws IOException
      Create a temporary file with the specified name.

      The name is broken into file name and suffix, and the parts are passed to File.createTempFile(String, String).

      File.deleteOnExit() is called on the resulting file before being returned by this method.

      Parameters:
      name - The file name
      Returns:
      A newly-created temporary file.
      Throws:
      IOException - Thrown by underlying stream.
    • createTempFile

      public static File createTempFile(String name, String contents) throws IOException
      Create a temporary file with the specified name and specified contents.

      The name is broken into file name and suffix, and the parts are passed to File.createTempFile(String, String).

      File.deleteOnExit() is called on the resulting file before being returned by this method.

      Parameters:
      name - The file name
      contents - The file contents.
      Returns:
      A newly-created temporary file.
      Throws:
      IOException - Thrown by underlying stream.
    • getBaseName

      public static String getBaseName(String name)
      Strips the extension from a file name.
      Parameters:
      name - The file name.
      Returns:
      The file name without the extension, or null if name was null.
    • getExtension

      public static String getExtension(String name)
      Returns the extension from a file name.
      Parameters:
      name - The file name.
      Returns:
      The the extension, or null if name was null.
    • exists

      public static boolean exists(File dir, String fileName)
      Returns true if the specified file exists in the specified directory.
      Parameters:
      dir - The directory.
      fileName - The file name.
      Returns:
      true if the specified file exists in the specified directory.
    • hasExtension

      public static boolean hasExtension(String name, String ext)
      Returns true if the specified file name contains the specified extension.
      Parameters:
      name - The file name.
      ext - The extension.
      Returns:
      true if the specified file name contains the specified extension.
    • getFileName

      public static String getFileName(String path)
      Given an arbitrary path, returns the file name portion of that path.
      Parameters:
      path - The path to check.
      Returns:
      The file name.