Package gr.zeus.util
Class IOHelper
- java.lang.Object
-
- gr.zeus.util.IOHelper
-
public final class IOHelper extends java.lang.Object
IO 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 boolean
copyFile(java.io.File fromFile, java.io.File toFile, boolean overwrite)
Copies a file to another location/file.static boolean
copyFile(java.lang.String fromName, java.lang.String toName, boolean overwrite)
Copies a file to another location/file.static void
createDirectoryTreeForFile(java.lang.String file)
Creates the complete directory structure for a complete FILE pathname.static java.lang.String
createDirectoryTreeForFolder(java.lang.String folder)
Creates the complete directory structure for a complete FOLDER pathname.static boolean
deleteDirectory(java.io.File dir)
Deletes all files and subdirectories under dir.static boolean
deleteDirectory(java.lang.String pathname)
Deletes all files and subdirectories under dir.static boolean
deleteFile(java.lang.String pathname)
Deletes a file.static boolean
fileOrDirectoryExists(java.lang.String pathname)
Determines if a file or directory exists.static boolean
isDirectory(java.lang.String pathname)
Determines if a directory exists.static boolean
isFile(java.lang.String pathname)
Determines if a file exists.static boolean
isTheSameFile(java.lang.String pathname1, java.lang.String pathname2)
Determines if two filename paths refer to the same file.static java.lang.String
readTxtFile(java.io.File f)
Reads a text file into a string.static java.lang.String
readTxtFile(java.lang.String pathname)
Reads a text file into a string.static void
saveTxtFile(java.io.File f, java.lang.String data, boolean append)
Saves a string to a text file.static void
saveTxtFile(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.IOException
Creates 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.IOException
Creates 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.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:
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:
true
if it exists.
-
isFile
public static boolean isFile(java.lang.String pathname)
Determines if a file exists.- Parameters:
pathname
- The file to check.- Returns:
true
if it exists.
-
isDirectory
public static boolean isDirectory(java.lang.String pathname)
Determines if a directory exists.- Parameters:
pathname
- The directory pathname.- Returns:
true
if it exists.
-
saveTxtFile
public static void saveTxtFile(java.lang.String pathname, java.lang.String data, boolean append) throws java.io.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:
java.io.IOException
-
saveTxtFile
public static void saveTxtFile(java.io.File f, java.lang.String data, boolean append) throws java.io.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:
java.io.IOException
-
readTxtFile
public static java.lang.String readTxtFile(java.lang.String pathname) throws java.io.IOException
Reads 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.IOException
Reads 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. 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
public static boolean deleteDirectory(java.lang.String pathname)
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
public static boolean deleteFile(java.lang.String pathname)
Deletes a file.- Parameters:
pathname
- The pathname to the file.- Returns:
true
if successful.
-
copyFile
public static boolean copyFile(java.lang.String fromName, java.lang.String toName, boolean overwrite) throws java.io.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:
java.io.IOException
-
copyFile
public static boolean copyFile(java.io.File fromFile, java.io.File toFile, boolean overwrite) throws java.io.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 orfalse
if not (possibly the file existed and 'overwrite' was not set).- Throws:
java.io.IOException
-
-