Package gr.zeus.util
Class IOHelper
java.lang.Object
gr.zeus.util.IOHelper
IO helper methods.
- Since:
- 1.0
- Author:
- Gregory Kotsaftis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCopies a file to another location/file.static booleanCopies a file to another location/file.static voidCreates the complete directory structure for a complete FILE pathname.static StringcreateDirectoryTreeForFolder(String folder) Creates the complete directory structure for a complete FOLDER pathname.static booleandeleteDirectory(File dir) Deletes all files and subdirectories under dir.static booleandeleteDirectory(String pathname) Deletes all files and subdirectories under dir.static booleandeleteFile(String pathname) Deletes a file.static booleanfileOrDirectoryExists(String pathname) Determines if a file or directory exists.static booleanisDirectory(String pathname) Determines if a directory exists.static booleanDetermines if a file exists.static booleanisTheSameFile(String pathname1, String pathname2) Determines if two filename paths refer to the same file.static StringreadTxtFile(File f) Reads a text file into a string.static StringreadTxtFile(String pathname) Reads a text file into a string.static voidsaveTxtFile(File f, String data, boolean append) Saves a string to a text file.static voidsaveTxtFile(String pathname, String data, boolean append) Saves a string to a text file.
-
Constructor Details
-
IOHelper
public IOHelper()
-
-
Method Details
-
createDirectoryTreeForFolder
Creates the complete directory structure for a complete FOLDER pathname.- Parameters:
folder- The folder pathname.- Returns:
- The folder pathname.
- Throws:
IOException
-
createDirectoryTreeForFile
Creates the complete directory structure for a complete FILE pathname.- Parameters:
file- The file pathname.- Throws:
IOException
-
isTheSameFile
Determines 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:
IOException-- See Also:
-
fileOrDirectoryExists
Determines if a file or directory exists.- Parameters:
pathname- The file or directory pathname.- Returns:
trueif it exists.
-
isFile
Determines if a file exists.- Parameters:
pathname- The file to check.- Returns:
trueif it exists.
-
isDirectory
Determines if a directory exists.- Parameters:
pathname- The directory pathname.- Returns:
trueif it exists.
-
saveTxtFile
Saves 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:
IOException
-
saveTxtFile
Saves 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:
IOException
-
readTxtFile
Reads a text file into a string.- Parameters:
pathname- The path to the text file.- Returns:
- The text in the file.
- Throws:
IOException
-
readTxtFile
Reads a text file into a string.- Parameters:
f- The file.- Returns:
- The text in the file.
- Throws:
IOException
-
deleteDirectory
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
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
Deletes a file.- Parameters:
pathname- The pathname to the file.- Returns:
trueif 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-trueto overwrite if the file already exists.- Returns:
trueif file copied orfalseif not (possibly the file existed and 'overwrite' was not set).- Throws:
IOException
-
copyFile
Copies 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:
IOException
-