Package gr.zeus.util
Class IOHelper
- java.lang.Object
-
- gr.zeus.util.IOHelper
-
public final class IOHelper extends java.lang.ObjectIO helper methods.- Since:
- 1.0
- Author:
- Gregory Kotsaftis
-
-
Constructor Summary
Constructors Constructor Description IOHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancopyFile(java.io.File fromFile, java.io.File toFile, boolean overwrite)Copies a file to another location/file.static booleancopyFile(java.lang.String fromName, java.lang.String toName, boolean overwrite)Copies a file to another location/file.static voidcreateDirectoryTreeForFile(java.lang.String file)Creates the complete directory structure for a complete FILE pathname.static java.lang.StringcreateDirectoryTreeForFolder(java.lang.String folder)Creates the complete directory structure for a complete FOLDER pathname.static booleandeleteDirectory(java.io.File dir)Deletes all files and subdirectories under dir.static booleandeleteDirectory(java.lang.String pathname)Deletes all files and subdirectories under dir.static booleandeleteFile(java.lang.String pathname)Deletes a file.static booleanfileOrDirectoryExists(java.lang.String pathname)Determines if a file or directory exists.static booleanisDirectory(java.lang.String pathname)Determines if a directory exists.static booleanisFile(java.lang.String pathname)Determines if a file exists.static booleanisTheSameFile(java.lang.String pathname1, java.lang.String pathname2)Determines if two filename paths refer to the same file.static java.lang.StringreadTxtFile(java.io.File f)Reads a text file into a string.static java.lang.StringreadTxtFile(java.lang.String pathname)Reads a text file into a string.static voidsaveTxtFile(java.io.File f, java.lang.String data, boolean append)Saves a string to a text file.static voidsaveTxtFile(java.lang.String pathname, java.lang.String data, boolean append)Saves a string to a text file.
-
-
-
Method Detail
-
createDirectoryTreeForFolder
public static java.lang.String createDirectoryTreeForFolder(java.lang.String folder) throws java.io.IOExceptionCreates the complete directory structure for a complete FOLDER pathname.- Parameters:
folder- The folder pathname.- Returns:
- The folder pathname.
- Throws:
java.io.IOException
-
createDirectoryTreeForFile
public static void createDirectoryTreeForFile(java.lang.String file) throws java.io.IOExceptionCreates the complete directory structure for a complete FILE pathname.- Parameters:
file- The file pathname.- Throws:
java.io.IOException
-
isTheSameFile
public static boolean isTheSameFile(java.lang.String pathname1, java.lang.String pathname2) throws java.io.IOExceptionDetermines if two filename paths refer to the same file.- Parameters:
pathname1- The first pathname.pathname2- The second pathname.- Returns:
trueif two filename paths refer to the same file.- Throws:
java.io.IOException-- See Also:
- http://javaalmanac.com/egs/java.io/Canonical.html
-
fileOrDirectoryExists
public static boolean fileOrDirectoryExists(java.lang.String pathname)
Determines if a file or directory exists.- Parameters:
pathname- The file or directory pathname.- Returns:
trueif it exists.
-
isFile
public static boolean isFile(java.lang.String pathname)
Determines if a file exists.- Parameters:
pathname- The file to check.- Returns:
trueif it exists.
-
isDirectory
public static boolean isDirectory(java.lang.String pathname)
Determines if a directory exists.- Parameters:
pathname- The directory pathname.- Returns:
trueif it exists.
-
saveTxtFile
public static void saveTxtFile(java.lang.String pathname, java.lang.String data, boolean append) throws java.io.IOExceptionSaves a string to a text file.- Parameters:
pathname- The pathname to the file.data- The string to be saved.append-trueif the string is to be appended to the end of existing text.- Throws:
java.io.IOException
-
saveTxtFile
public static void saveTxtFile(java.io.File f, java.lang.String data, boolean append) throws java.io.IOExceptionSaves a string to a text file.- Parameters:
f- The file.data- The string to save.append-trueif the string is to be appended to the end of existing text.- Throws:
java.io.IOException
-
readTxtFile
public static java.lang.String readTxtFile(java.lang.String pathname) throws java.io.IOExceptionReads a text file into a string.- Parameters:
pathname- The path to the text file.- Returns:
- The text in the file.
- Throws:
java.io.IOException
-
readTxtFile
public static java.lang.String readTxtFile(java.io.File f) throws java.io.IOExceptionReads a text file into a string.- Parameters:
f- The file.- Returns:
- The text in the file.
- Throws:
java.io.IOException
-
deleteDirectory
public static boolean deleteDirectory(java.io.File dir)
Deletes all files and subdirectories under dir. Returnstrueif all deletions were successful. If a deletion fails, the method stops attempting to delete and returnsfalse.- Parameters:
dir- The directory to delete from.- Returns:
trueif all deletions were successful.
-
deleteDirectory
public static boolean deleteDirectory(java.lang.String pathname)
Deletes all files and subdirectories under dir. Returnstrueif all deletions were successful. If a deletion fails, the method stops attempting to delete and returnsfalse.- Parameters:
pathname- The path to the directory.- Returns:
trueif all deletions were successful.
-
deleteFile
public static boolean deleteFile(java.lang.String pathname)
Deletes a file.- Parameters:
pathname- The pathname to the file.- Returns:
trueif successful.
-
copyFile
public static boolean copyFile(java.lang.String fromName, java.lang.String toName, boolean overwrite) throws java.io.IOExceptionCopies a file to another location/file.- Parameters:
fromName- The file to copy from.toName- The file to copy to.overwrite-trueto overwrite if the file already exists.- Returns:
trueif file copied orfalseif not (possibly the file existed and 'overwrite' was not set).- Throws:
java.io.IOException
-
copyFile
public static boolean copyFile(java.io.File fromFile, java.io.File toFile, boolean overwrite) throws java.io.IOExceptionCopies a file to another location/file.- Parameters:
fromFile- The file to copy from.toFile- The file to copy to.overwrite-trueto overwrite if the file already exists.- Returns:
trueif file copied orfalseif not (possibly the file existed and 'overwrite' was not set).- Throws:
java.io.IOException
-
-