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 boolean
Copies a file to another location/file.static boolean
Copies a file to another location/file.static void
Creates the complete directory structure for a complete FILE pathname.static String
createDirectoryTreeForFolder
(String folder) Creates the complete directory structure for a complete FOLDER pathname.static boolean
deleteDirectory
(File dir) Deletes all files and subdirectories under dir.static boolean
deleteDirectory
(String pathname) Deletes all files and subdirectories under dir.static boolean
deleteFile
(String pathname) Deletes a file.static boolean
fileOrDirectoryExists
(String pathname) Determines if a file or directory exists.static boolean
isDirectory
(String pathname) Determines if a directory exists.static boolean
Determines if a file exists.static boolean
isTheSameFile
(String pathname1, String pathname2) Determines if two filename paths refer to the same file.static String
readTxtFile
(File f) Reads a text file into a string.static String
readTxtFile
(String pathname) Reads a text file into a string.static void
saveTxtFile
(File f, String data, boolean append) Saves a string to a text file.static void
saveTxtFile
(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:
true
if 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:
true
if it exists.
-
isFile
Determines if a file exists.- Parameters:
pathname
- The file to check.- Returns:
true
if it exists.
-
isDirectory
Determines if a directory exists.- Parameters:
pathname
- The directory pathname.- Returns:
true
if it exists.
-
saveTxtFile
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
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
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. Returnstrue
if all deletions were successful. If a deletion fails, the method stops attempting to delete and returnsfalse
.- Parameters:
dir
- The directory to delete from.- Returns:
true
if all deletions were successful.
-
deleteDirectory
Deletes all files and subdirectories under dir. Returnstrue
if all deletions were successful. If a deletion fails, the method stops attempting to delete and returnsfalse
.- Parameters:
pathname
- The path to the directory.- Returns:
true
if all deletions were successful.
-
deleteFile
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 orfalse
if 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
-true
to overwrite if the file already exists.- Returns:
true
if file copied orfalse
if not (possibly the file existed and 'overwrite' was not set).- Throws:
IOException
-