Package gr.zeus.util

Class IOHelper

java.lang.Object
gr.zeus.util.IOHelper

public final class IOHelper extends Object
IO helper methods.

Since:
1.0
Author:
Gregory Kotsaftis
  • Constructor Details

    • IOHelper

      public IOHelper()
  • Method Details

    • createDirectoryTreeForFolder

      public static String createDirectoryTreeForFolder(String folder) throws IOException
      Creates the complete directory structure for a complete FOLDER pathname.

      Parameters:
      folder - The folder pathname.

      Returns:
      The folder pathname.

      Throws:
      IOException
    • createDirectoryTreeForFile

      public static void createDirectoryTreeForFile(String file) throws IOException
      Creates the complete directory structure for a complete FILE pathname.

      Parameters:
      file - The file pathname.

      Throws:
      IOException
    • isTheSameFile

      public static boolean isTheSameFile(String pathname1, String pathname2) throws IOException
      Determines if two filename paths refer to the same file.

      Parameters:
      pathname1 - The first pathname.
      pathname2 - The second pathname.

      Returns:
      true if two filename paths refer to the same file.

      Throws:
      IOException -

      See Also:
    • fileOrDirectoryExists

      public static boolean fileOrDirectoryExists(String pathname)
      Determines if a file or directory exists.

      Parameters:
      pathname - The file or directory pathname.

      Returns:
      true if it exists.
    • isFile

      public static boolean isFile(String pathname)
      Determines if a file exists.

      Parameters:
      pathname - The file to check.

      Returns:
      true if it exists.
    • isDirectory

      public static boolean isDirectory(String pathname)
      Determines if a directory exists.

      Parameters:
      pathname - The directory pathname.

      Returns:
      true if it exists.
    • saveTxtFile

      public static void saveTxtFile(String pathname, String data, boolean append) throws IOException
      Saves a string to a text file.

      Parameters:
      pathname - The pathname to the file.
      data - The string to be saved.
      append - true if the string is to be appended to the end of existing text.

      Throws:
      IOException
    • saveTxtFile

      public static void saveTxtFile(File f, String data, boolean append) throws IOException
      Saves a string to a text file.

      Parameters:
      f - The file.
      data - The string to save.
      append - true if the string is to be appended to the end of existing text.

      Throws:
      IOException
    • readTxtFile

      public static String readTxtFile(String pathname) throws IOException
      Reads a text file into a string.

      Parameters:
      pathname - The path to the text file.

      Returns:
      The text in the file.

      Throws:
      IOException
    • readTxtFile

      public static String readTxtFile(File f) throws IOException
      Reads a text file into a string.

      Parameters:
      f - The file.

      Returns:
      The text in the file.

      Throws:
      IOException
    • deleteDirectory

      public static boolean deleteDirectory(File dir)
      Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

      Parameters:
      dir - The directory to delete from.

      Returns:
      true if all deletions were successful.
    • deleteDirectory

      public static boolean deleteDirectory(String pathname)
      Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

      Parameters:
      pathname - The path to the directory.

      Returns:
      true if all deletions were successful.
    • deleteFile

      public static boolean deleteFile(String pathname)
      Deletes a file.

      Parameters:
      pathname - The pathname to the file.

      Returns:
      true if successful.
    • copyFile

      public static boolean copyFile(String fromName, String toName, boolean overwrite) throws IOException
      Copies a file to another location/file.

      Parameters:
      fromName - The file to copy from.
      toName - The file to copy to.
      overwrite - true to overwrite if the file already exists.

      Returns:
      true if file copied or false if not (possibly the file existed and 'overwrite' was not set).

      Throws:
      IOException
    • copyFile

      public static boolean copyFile(File fromFile, File toFile, boolean overwrite) throws IOException
      Copies a file to another location/file.

      Parameters:
      fromFile - The file to copy from.
      toFile - The file to copy to.
      overwrite - true to overwrite if the file already exists.

      Returns:
      true if file copied or false if not (possibly the file existed and 'overwrite' was not set).

      Throws:
      IOException