Package snap.util

Class FileUtils

java.lang.Object
snap.util.FileUtils

public class FileUtils extends Object
Utility methods for file.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static File
    copyFile(File aSource, File aDest)
    Copies a file from one location to another.
    static File
    Copies a file from one location to another with exception suppression.
    static boolean
    Deletes a directory.
    static File
    getAppDataDir(String aName, boolean doCreate)
    Returns the AppData or Application Support directory file.
    static byte[]
    getBytes(File aFile)
    Returns bytes for a file.
    static byte[]
    Returns bytes for a file.
    static File
    getDirForSource(Object aSource, boolean doCreate)
    Returns a directory for given source (path, url, string path) with option to create if missing.
    static File
    getFile(Object aSource)
    Returns a File object from a source, if one can be divined.
    static File
    Returns the temp directory.
    static File
    Creates a file in the temp directory.
    static File
    getUserHomeDir(String aName, boolean doCreate)
    Returns a file for named directory in the user's home directory (with option to create).
    static boolean
    move(File aSource, File aDest)
    Moves a file.
    static void
    openFile(File aFile)
    Tries to open the given file name with the platform reader.
    static void
    Tries to open the given file name with the platform reader.
    static void
    unzipFile(File aFile)
    Unzips the given file into the destination file.
    static void
    writeBytes(File aFile, byte[] theBytes)
    Writes the given bytes (within the specified range) to the given file.
    static void
    writeBytesSafely(File aFile, byte[] theBytes)
    Writes the given bytes (within the specified range) to the given file, with an option for doing it "safely".

    Methods inherited from class java.lang.Object

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

    • FileUtils

      public FileUtils()
  • Method Details

    • getFile

      public static File getFile(Object aSource)
      Returns a File object from a source, if one can be divined.
    • getDirForSource

      public static File getDirForSource(Object aSource, boolean doCreate)
      Returns a directory for given source (path, url, string path) with option to create if missing.
    • openFile

      public static void openFile(File aFile)
      Tries to open the given file name with the platform reader.
    • openFile

      public static void openFile(String aName)
      Tries to open the given file name with the platform reader.
    • getBytes

      public static byte[] getBytes(File aFile)
      Returns bytes for a file.
    • getBytesOrThrow

      public static byte[] getBytesOrThrow(File aFile) throws IOException
      Returns bytes for a file.
      Throws:
      IOException
    • writeBytes

      public static void writeBytes(File aFile, byte[] theBytes) throws IOException
      Writes the given bytes (within the specified range) to the given file.
      Throws:
      IOException
    • writeBytesSafely

      public static void writeBytesSafely(File aFile, byte[] theBytes) throws IOException
      Writes the given bytes (within the specified range) to the given file, with an option for doing it "safely".
      Throws:
      IOException
    • getTempDir

      public static File getTempDir()
      Returns the temp directory.
    • getTempFile

      public static File getTempFile(String aName)
      Creates a file in the temp directory.
    • getUserHomeDir

      public static File getUserHomeDir(String aName, boolean doCreate)
      Returns a file for named directory in the user's home directory (with option to create).
    • getAppDataDir

      public static File getAppDataDir(String aName, boolean doCreate)
      Returns the AppData or Application Support directory file.
    • copyFile

      public static File copyFile(File aSource, File aDest) throws IOException
      Copies a file from one location to another.
      Throws:
      IOException
    • copyFileSafe

      public static File copyFileSafe(File in, File out)
      Copies a file from one location to another with exception suppression.
    • move

      public static boolean move(File aSource, File aDest) throws IOException
      Moves a file.
      Throws:
      IOException
    • deleteDeep

      public static boolean deleteDeep(File aFile)
      Deletes a directory.
    • unzipFile

      public static void unzipFile(File aFile) throws IOException
      Unzips the given file into the destination file.
      Throws:
      IOException