Package adams.core.io
Class FileUtils
- java.lang.Object
-
- adams.core.io.FileUtils
-
public class FileUtils extends Object
Utility class for I/O related actions.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static intBINARY_CHECK_BUFFER_SIZEthe length of the buffer for binary checks.static StringFILENAMEthe properties file.protected static StringFILENAME_CHARSvalid characters for filenames.protected static String[]IGNORED_EXTENSION_SUFFIXESthe ignored extension suffixes.protected static Propertiesm_Propertiesthe properties.protected static IntegerMAX_EXTENSION_LENGTHthe maximum length for an extension.
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]absolutePath(File[] files)Returns the absolute paths.static String[]absolutePath(String[] files)Returns the absolute paths.static voidcloseQuietly(Closeable closeable)Closes the closeable object, if possible, suppressing any exception.static voidcloseQuietly(InputStream is)Closes the stream, if possible, suppressing any exception.static voidcloseQuietly(OutputStream os)Closes the stream, if possible, suppressing any exception.static voidcloseQuietly(Reader reader)Closes the reader, if possible, suppressing any exception.static voidcloseQuietly(Writer writer)Closes the writer, if possible, suppressing any exception.static StringconvertPlaceholder(String file)Ensures that the file string no longer contains a placeholder.static booleancopy(File sourceLocation, File targetLocation)Copies the file/directory (recursively).static booleancopyOrMove(File sourceLocation, File targetLocation, boolean move, boolean atomic)Copies or moves files and directories (recursively).static StringcreateFilename(String s, String replace)Replaces all characters that would create problems on a filesystem.static StringcreatePartialFilename(File file, int numParentDirs)Creates a partial filename for the given file, based on how many parent directories should be included.static booleandelete(File file)Deletes the specified file.static booleandelete(String file)Deletes the specified file.static booleandirExists(File dir)Checks whether the directory (not file!)static booleandirExists(String dirname)Checks whether the directory (not file!)static booleandirOrParentDirExists(File file)Checks whether the directory exists.static booleandirOrParentDirExists(String filename)Checks whether the directory exists.static booleanfileExists(File file)Checks whether the file (not directory!)static booleanfileExists(String filename)Checks whether the file (not directory!)static StringfixExecutable(String executable)Adjusts the extension according to the platform.static intgetDirectoryDepth(File file)Returns the number of directories that this file object contains.static StringgetExtension(File file)Returns the extension of the file, if any.static StringgetExtension(String filename)Returns the extension of the file, if any.static String[]getExtensions(File file)Returns the extensions of the file, if any.static String[]getExtensions(String filename)Returns the extensions of the file, if any.static StringgetFileNameChars()Returns the characters that can be used in filenames.static String[]getIgnoredExtensionSuffixes()Returns the extension suffixes that get ignored in determining a file's extension.static intgetMaxExtensionLength()Returns the maximum length of extensions.protected static PropertiesgetProperties()Returns the properties.static booleanisBinary(File file)Returns whether the file is (most likely) a binary one.static booleanisBinary(String filename)Returns whether the file is (most likely) a binary one.static booleanisDirEmpty(File dir)Checks whether the directory is empty.static booleanisDirEmpty(File dir, String regExp)Checks whether the directory is empty.static booleanisDirEmpty(String dir)Checks whether the directory is empty.static booleanisDirEmpty(String dir, String regExp)Checks whether the directory is empty.static booleanisOpen(File file)Checks whether the file is open/accessed by another process (Windows/*nix).static booleanisOpenNonWindows(File file)Checks whether the file is open/accessed by another process (Windows/*nix).static booleanisOpenWindows(File file)Checks whether the file is open/accessed by another process.static byte[]loadFromBinaryFile(File file)Loads the binary file.static byte[]loadFromBinaryFile(File file, int max)Loads the specified maximum number of bytes from a binary file.static byte[]loadFromBinaryStream(InputStream in)Returns bytes from the given stream, null in case of an error.static List<String>loadFromFile(File file)Returns the content of the given file, null in case of an error.static List<String>loadFromFile(File file, String encoding)Returns the content of the given file, null in case of an error.static List<String>loadFromFile(File file, String encoding, boolean handleGzip)Returns the content of the given file, null in case of an error.static StringloadHexFromBinaryFile(File file)Loads the binary file and returns the hexadecimal representation.static StringloadHexFromBinaryFile(File file, int columns)Loads the binary file and returns the hexadecimal representation.static List<String>loadLinesFromStream(InputStream in)Returns lines from the given stream (split on newline), null in case of an error.static List<String>loadLinesFromStream(InputStream in, String encoding)Returns lines from the given stream (split on newline), null in case of an error.static booleanmove(File sourceLocation, File targetLocation)Moves the file/directory (recursively).static booleanmove(File sourceLocation, File targetLocation, boolean atomic)Moves the file/directory (recursively).static StringquoteExecutable(String executable)Surrounds the executable with double quotes if a blank is in the path.static StringrelativePath(File parent, File file)Returns the part of the file that is relative to the parent.static String[]relativePath(File parent, File[] files)Returns the part of the files that is relative to the parent.static StringrelativePath(String parent, String file)Returns the part of the file that is relative to the parent.static String[]relativePath(String parent, String[] files)Returns the part of the files that is relative to the parent.static StringremoveAllByteOrderMarks(String s)Removes byte order marks (BOMs) from the start of the string (if present).static StringremoveByteOrderMarks(String s)Removes byte order marks (BOMs) from the start of the string (if present).static StringremoveIgnoredExtensionSuffixes(String filename)Removes any ignored extension suffixes from the filename.static StringremoveUTF8BOM(String s)Removes a UTF-8 BOM.static voidremoveUTF8BOM(StringBuilder s)Removes a UTF-8 BOM.static PlaceholderFilereplaceExtension(PlaceholderFile file, String newExt)Replaces the extension of the given file with the new one.static FilereplaceExtension(File file, String newExt)Replaces the extension of the given file with the new one.static StringreplaceExtension(String file, String newExt)Replaces the extension of the given file with the new one.static booleansaveToFile(String[] content, File file)Saves the content to the given file.static booleansaveToFile(List<String> content, File file)Saves the content to the given file.static booleansaveToFile(List<String> content, File file, String encoding)Saves the content to the given file.static StringsaveToFileMsg(List<String> content, File file, String encoding)Saves the content to the given file.static File[]toFileArray(Object input)Turns String, String[], File, File[] into aFilearray.static PlaceholderFile[]toPlaceholderFileArray(Object input)Turns String, String[], File, File[] into aPlaceholderFilearray.static String[]toStringArray(Object input)Turns String, String[], File, File[] into aStringarray.static StringuseForwardSlashes(String path)Converts backslashes in a path to forwards slashes.static booleanwriteToBinaryFile(String filename, byte[] data)Writes the binary data to the specified file.static booleanwriteToBinaryFile(String filename, byte[] data, boolean append)Writes the binary data to the specified file.static booleanwriteToFile(String filename, Object obj)Writes the given object to the specified file.static booleanwriteToFile(String filename, Object obj, boolean append)Writes the given object to the specified file.static booleanwriteToFile(String filename, Object obj, boolean append, String encoding)Writes the given object to the specified file.static booleanwriteToFile(String filename, Object obj, String encoding)Writes the given object to the specified file.static StringwriteToFileMsg(String filename, Object obj, boolean append, String encoding)Writes the given object to the specified file.
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the properties file.- See Also:
- Constant Field Values
-
m_Properties
protected static Properties m_Properties
the properties.
-
FILENAME_CHARS
protected static String FILENAME_CHARS
valid characters for filenames.
-
MAX_EXTENSION_LENGTH
protected static Integer MAX_EXTENSION_LENGTH
the maximum length for an extension.
-
IGNORED_EXTENSION_SUFFIXES
protected static String[] IGNORED_EXTENSION_SUFFIXES
the ignored extension suffixes.
-
BINARY_CHECK_BUFFER_SIZE
public static final int BINARY_CHECK_BUFFER_SIZE
the length of the buffer for binary checks.- See Also:
- Constant Field Values
-
-
Method Detail
-
getProperties
protected static Properties getProperties()
Returns the properties.- Returns:
- the properties
-
getFileNameChars
public static String getFileNameChars()
Returns the characters that can be used in filenames.- Returns:
- the characters (in single string)
-
getMaxExtensionLength
public static int getMaxExtensionLength()
Returns the maximum length of extensions.- Returns:
- the max length
-
getIgnoredExtensionSuffixes
public static String[] getIgnoredExtensionSuffixes()
Returns the extension suffixes that get ignored in determining a file's extension. Examples are "gz" or "bz2".- Returns:
- the suffixes
-
removeUTF8BOM
public static void removeUTF8BOM(StringBuilder s)
Removes a UTF-8 BOM.- Parameters:
s- the current string
-
removeUTF8BOM
public static String removeUTF8BOM(String s)
Removes a UTF-8 BOM.- Parameters:
s- the string to process- Returns:
- the (potentially) updated string
-
removeByteOrderMarks
public static String removeByteOrderMarks(String s)
Removes byte order marks (BOMs) from the start of the string (if present). For UTF-16 and UTF-32.- Parameters:
s- the string to process- Returns:
- the processed string
-
removeAllByteOrderMarks
public static String removeAllByteOrderMarks(String s)
Removes byte order marks (BOMs) from the start of the string (if present). For UTF-8, UTF-16 and UTF-32.- Parameters:
s- the string to process- Returns:
- the processed string
-
loadLinesFromStream
public static List<String> loadLinesFromStream(InputStream in)
Returns lines from the given stream (split on newline), null in case of an error.- Parameters:
in- the stream to load from- Returns:
- the content/lines of the file
-
loadLinesFromStream
public static List<String> loadLinesFromStream(InputStream in, String encoding)
Returns lines from the given stream (split on newline), null in case of an error.- Parameters:
in- the stream to load fromencoding- the encoding to use, null to use default- Returns:
- the content/lines of the file
-
loadFromFile
public static List<String> loadFromFile(File file)
Returns the content of the given file, null in case of an error. Also handles gzip compressed files (uses newline to split into lines).- Parameters:
file- the file to load- Returns:
- the content/lines of the file
-
loadFromFile
public static List<String> loadFromFile(File file, String encoding)
Returns the content of the given file, null in case of an error. Also handles gzip compressed files (uses newline to split into lines).- Parameters:
file- the file to loadencoding- the encoding to use, null to use default- Returns:
- the content/lines of the file, null in case of an error
-
loadFromFile
public static List<String> loadFromFile(File file, String encoding, boolean handleGzip)
Returns the content of the given file, null in case of an error. Also handles gzip compressed files (uses newline to split into lines).- Parameters:
file- the file to loadencoding- the encoding to use, null to use default- Returns:
- the content/lines of the file, null in case of an error
-
loadFromBinaryFile
public static byte[] loadFromBinaryFile(File file)
Loads the binary file.- Parameters:
file- the file to load- Returns:
- the binary content, null in case of an error
-
loadFromBinaryFile
public static byte[] loadFromBinaryFile(File file, int max)
Loads the specified maximum number of bytes from a binary file.- Parameters:
file- the file to loadmax- the maximum number of bytes to load- Returns:
- the binary content, null in case of an error
-
loadFromBinaryStream
public static byte[] loadFromBinaryStream(InputStream in)
Returns bytes from the given stream, null in case of an error.- Parameters:
in- the stream to load from- Returns:
- the content/lines of the file
-
loadHexFromBinaryFile
public static String loadHexFromBinaryFile(File file)
Loads the binary file and returns the hexadecimal representation. Uses 16 columns.- Parameters:
file- the file to load- Returns:
- the binary content as hex, null in case of an error
-
loadHexFromBinaryFile
public static String loadHexFromBinaryFile(File file, int columns)
Loads the binary file and returns the hexadecimal representation.- Parameters:
file- the file to loadcolumns- the number of columns to generate- Returns:
- the binary content as hex, null in case of an error
-
saveToFile
public static boolean saveToFile(String[] content, File file)
Saves the content to the given file.- Parameters:
content- the content to savefile- the file to save the content to- Returns:
- true if successfully saved
-
saveToFile
public static boolean saveToFile(List<String> content, File file)
Saves the content to the given file.- Parameters:
content- the content to savefile- the file to save the content to- Returns:
- true if successfully saved
-
saveToFile
public static boolean saveToFile(List<String> content, File file, String encoding)
Saves the content to the given file.- Parameters:
content- the content to savefile- the file to save the content toencoding- the encoding to use, null for default- Returns:
- true if successfully saved
-
saveToFileMsg
public static String saveToFileMsg(List<String> content, File file, String encoding)
Saves the content to the given file.- Parameters:
content- the content to savefile- the file to save the content toencoding- the encoding to use, null for default- Returns:
- null if successfully saved, otherwise error message
-
writeToBinaryFile
public static boolean writeToBinaryFile(String filename, byte[] data)
Writes the binary data to the specified file. The file is always overwritten.- Parameters:
filename- the file to write todata- the data to write- Returns:
- true if writing was successful
-
writeToBinaryFile
public static boolean writeToBinaryFile(String filename, byte[] data, boolean append)
Writes the binary data to the specified file.- Parameters:
filename- the file to write todata- the data to writeappend- whether to append the file- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(String filename, Object obj)
Writes the given object to the specified file. The object is always appended.- Parameters:
filename- the file to write toobj- the object to write- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(String filename, Object obj, String encoding)
Writes the given object to the specified file. The object is always appended.- Parameters:
filename- the file to write toobj- the object to writeencoding- the encoding to use, null for default- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(String filename, Object obj, boolean append)
Writes the given object to the specified file. The message is either appended or replaces the current content of the file.- Parameters:
filename- the file to write toobj- the object to writeappend- whether to append the message or not- Returns:
- true if writing was successful
-
writeToFile
public static boolean writeToFile(String filename, Object obj, boolean append, String encoding)
Writes the given object to the specified file. The message is either appended or replaces the current content of the file.- Parameters:
filename- the file to write toobj- the object to writeappend- whether to append the message or notencoding- the encoding to use, null for default- Returns:
- true if writing was successful
-
writeToFileMsg
public static String writeToFileMsg(String filename, Object obj, boolean append, String encoding)
Writes the given object to the specified file. The message is either appended or replaces the current content of the file.- Parameters:
filename- the file to write toobj- the object to writeappend- whether to append the message or notencoding- the encoding to use, null for default- Returns:
- null if writing was successful, otherwise error message
-
copyOrMove
public static boolean copyOrMove(File sourceLocation, File targetLocation, boolean move, boolean atomic) throws IOException
Copies or moves files and directories (recursively). If targetLocation does not exist, it will be created.
Original code from Java-Tips.org.- Parameters:
sourceLocation- the source file/dirtargetLocation- the target file/dirmove- if true then the source files/dirs get deleted as soon as copying finishedatomic- whether to perform an atomic move operation- Returns:
- false if failed to delete when moving or failed to create target directory
- Throws:
IOException- if copying/moving fails
-
copy
public static boolean copy(File sourceLocation, File targetLocation) throws IOException
Copies the file/directory (recursively).- Parameters:
sourceLocation- the source file/dirtargetLocation- the target file/dir- Returns:
- if successfully copied
- Throws:
IOException- if copying fails
-
move
public static boolean move(File sourceLocation, File targetLocation) throws IOException
Moves the file/directory (recursively).- Parameters:
sourceLocation- the source file/dirtargetLocation- the target file/dir- Returns:
- if successfully moved
- Throws:
IOException- if moving fails
-
move
public static boolean move(File sourceLocation, File targetLocation, boolean atomic) throws IOException
Moves the file/directory (recursively).- Parameters:
sourceLocation- the source file/dirtargetLocation- the target file/diratomic- whether to perform an atomic move operation- Returns:
- if successfully moved
- Throws:
IOException- if moving fails
-
delete
public static boolean delete(String file)
Deletes the specified file. If the file represents a directory, then this will get deleted recursively.- Parameters:
file- the file/dir to delete- Returns:
- true if successfully deleted
-
delete
public static boolean delete(File file)
Deletes the specified file. If the file represents a directory, then this will get deleted recursively.- Parameters:
file- the file/dir to delete- Returns:
- true if successfully deleted
-
createFilename
public static String createFilename(String s, String replace)
Replaces all characters that would create problems on a filesystem. The string is to be expected a filename without a path.- Parameters:
s- the string to processreplace- the character to replace "invalid" characters with, use empty string to strip "invalid" characters instead of replacing them.- Returns:
- the processed string
-
getDirectoryDepth
public static int getDirectoryDepth(File file)
Returns the number of directories that this file object contains. E.g.: /home/blah/some/where.txt will return 3. /blah.txt returns 0.- Parameters:
file- the file
-
createPartialFilename
public static String createPartialFilename(File file, int numParentDirs)
Creates a partial filename for the given file, based on how many parent directories should be included. Examples:createPartialFilename(new File("/home/some/where/file.txt"), -1) = /home/some/where/file.txt createPartialFilename(new File("/home/some/where/file.txt"), 0) = file.txt createPartialFilename(new File("/home/some/where/file.txt"), 1) = where/file.txt createPartialFilename(new File("/home/some/where/file.txt"), 2) = some/where/file.txt- Parameters:
file- the file to create the partial filename fornumParentDirs- the number of parent directories to include in the partial name, -1 returns the absolute filename- Returns:
- the generated filename
-
isDirEmpty
public static boolean isDirEmpty(File dir)
Checks whether the directory is empty.- Parameters:
dir- the directory to check- Returns:
- true if empty
-
isDirEmpty
public static boolean isDirEmpty(String dir)
Checks whether the directory is empty.- Parameters:
dir- the directory to check- Returns:
- true if empty
-
isDirEmpty
public static boolean isDirEmpty(File dir, String regExp)
Checks whether the directory is empty.- Parameters:
dir- the directory to checkregExp- a regular expression to look for, use null to ignore- Returns:
- true if empty
-
isDirEmpty
public static boolean isDirEmpty(String dir, String regExp)
Checks whether the directory is empty.- Parameters:
dir- the directory to checkregExp- a regular expression to look for, use null to ignore- Returns:
- true if empty or directory does not exist
-
fixExecutable
public static String fixExecutable(String executable)
Adjusts the extension according to the platform. For Windows it automatically adds ".exe" it neither ".com" nor ".exe" extension present. For other platforms it removes ".exe" and ".com".- Parameters:
executable- the executable (full path or just filename) to process- Returns:
- the processed executable
-
quoteExecutable
public static String quoteExecutable(String executable)
Surrounds the executable with double quotes if a blank is in the path.- Parameters:
executable- the executable (full path, no parameters)- Returns:
- the processed executable
-
removeIgnoredExtensionSuffixes
public static String removeIgnoredExtensionSuffixes(String filename)
Removes any ignored extension suffixes from the filename.- Parameters:
filename- the filename to process- Returns:
- the processed filename
-
getExtension
public static String getExtension(File file)
Returns the extension of the file, if any.- Parameters:
file- the file to get the extension from- Returns:
- the extension (no dot), null if none available
-
getExtension
public static String getExtension(String filename)
Returns the extension of the file, if any.- Parameters:
filename- the file to get the extension from- Returns:
- the extension (no dot), null if none available
-
getExtensions
public static String[] getExtensions(File file)
Returns the extensions of the file, if any. Returns "txt.gz" and "gz", for instance, for file "hello_world.txt.gz". The longer extension always comes first.- Parameters:
file- the file to get the extensions from- Returns:
- the extensions (no dot), null if none available
-
getExtensions
public static String[] getExtensions(String filename)
Returns the extensions of the file, if any. Removes ignored file extension suffixes like "gz" first.- Parameters:
filename- the file to get the extensions from- Returns:
- the extensions (no dot), null if none available
- See Also:
getIgnoredExtensionSuffixes()
-
replaceExtension
public static File replaceExtension(File file, String newExt)
Replaces the extension of the given file with the new one. Leave the new extension empty if you want to remove the extension. Always removes ignored extension suffixes first from the filename.- Parameters:
file- the file to replace the extension fornewExt- the new extension (incl dot), empty string to remove extension- Returns:
- the updated file
- See Also:
getIgnoredExtensionSuffixes()
-
replaceExtension
public static PlaceholderFile replaceExtension(PlaceholderFile file, String newExt)
Replaces the extension of the given file with the new one. Leave the new extension empty if you want to remove the extension. Always removes ignored extension suffixes first from the filename.- Parameters:
file- the file to replace the extension fornewExt- the new extension (incl dot), empty string to remove extension- Returns:
- the updated file
- See Also:
getIgnoredExtensionSuffixes()
-
replaceExtension
public static String replaceExtension(String file, String newExt)
Replaces the extension of the given file with the new one. Leave the new extension empty if you want to remove the extension. Always removes ignored extension suffixes first from the filename.- Parameters:
file- the file to replace the extension fornewExt- the new extension (incl dot), empty string to remove extension- Returns:
- the updated file
- See Also:
getIgnoredExtensionSuffixes()
-
isBinary
public static boolean isBinary(String filename)
Returns whether the file is (most likely) a binary one.- Parameters:
filename- the file to check- Returns:
- true if a binary file
-
isBinary
public static boolean isBinary(File file)
Returns whether the file is (most likely) a binary one. Reads the first kb and analyzes the bytes (skips tab, cr, lf).- Parameters:
file- the file to check- Returns:
- true if a binary file
-
convertPlaceholder
public static String convertPlaceholder(String file)
Ensures that the file string no longer contains a placeholder.- Parameters:
file- the file name to process- Returns:
- the "purged" file name
-
toPlaceholderFileArray
public static PlaceholderFile[] toPlaceholderFileArray(Object input)
Turns String, String[], File, File[] into aPlaceholderFilearray.- Parameters:
input- the input- Returns:
- the
PlaceholderFilearray - Throws:
IllegalArgumentException- if unsupported input class
-
toFileArray
public static File[] toFileArray(Object input)
Turns String, String[], File, File[] into aFilearray. Ensures that strings don't contain placeholders andFileobjects aren'tPlaceholderFileobjects.- Parameters:
input- the input- Returns:
- the
Filearray - Throws:
IllegalArgumentException- if unsupported input class
-
toStringArray
public static String[] toStringArray(Object input)
Turns String, String[], File, File[] into aStringarray. Ensures that strings don't contain placeholders.- Parameters:
input- the input- Returns:
- the
Stringarray - Throws:
IllegalArgumentException- if unsupported input class
-
useForwardSlashes
public static String useForwardSlashes(String path)
Converts backslashes in a path to forwards slashes. However, leaves UNC path prefix "\\" intact.- Parameters:
path- the path/filename to convert- Returns:
- the path/filename with forward slashes
-
closeQuietly
public static void closeQuietly(InputStream is)
Closes the stream, if possible, suppressing any exception.- Parameters:
is- the stream to close
-
closeQuietly
public static void closeQuietly(OutputStream os)
Closes the stream, if possible, suppressing any exception.- Parameters:
os- the stream to close
-
closeQuietly
public static void closeQuietly(Reader reader)
Closes the reader, if possible, suppressing any exception.- Parameters:
reader- the reader to close
-
closeQuietly
public static void closeQuietly(Writer writer)
Closes the writer, if possible, suppressing any exception.- Parameters:
writer- the writer to close
-
closeQuietly
public static void closeQuietly(Closeable closeable)
Closes the closeable object, if possible, suppressing any exception.- Parameters:
closeable- the closeable object to close
-
isOpen
public static boolean isOpen(File file)
Checks whether the file is open/accessed by another process (Windows/*nix).- Parameters:
file- the file to check- Returns:
- true if still open/accessed by another process
-
isOpenNonWindows
public static boolean isOpenNonWindows(File file)
Checks whether the file is open/accessed by another process (Windows/*nix).- Parameters:
file- the file to check- Returns:
- true if still open/accessed by another process
-
isOpenWindows
public static boolean isOpenWindows(File file)
Checks whether the file is open/accessed by another process.- Parameters:
file- the file to check- Returns:
- true if still open/accessed by another process
-
fileExists
public static boolean fileExists(String filename)
Checks whether the file (not directory!) exists.- Parameters:
filename- the filename to check- Returns:
- true if file exists
-
fileExists
public static boolean fileExists(File file)
Checks whether the file (not directory!) exists.- Parameters:
file- the file to check- Returns:
- true if file exists
-
dirExists
public static boolean dirExists(String dirname)
Checks whether the directory (not file!) exists.- Parameters:
dirname- the directory to check- Returns:
- true if file exists
-
dirExists
public static boolean dirExists(File dir)
Checks whether the directory (not file!) exists.- Parameters:
dir- the directory to check- Returns:
- true if file exists
-
dirOrParentDirExists
public static boolean dirOrParentDirExists(String filename)
Checks whether the directory exists. If this file object represents a file, then the parent directory is checked.- Parameters:
filename- the filename to check- Returns:
- true if directory exists
-
dirOrParentDirExists
public static boolean dirOrParentDirExists(File file)
Checks whether the directory exists. If this file object represents a file, then the parent directory is checked.- Parameters:
file- the file object to check- Returns:
- true if directory exists
-
relativePath
public static String[] relativePath(File parent, File[] files)
Returns the part of the files that is relative to the parent. If the files do not start with the parent, it will return the absolute paths of the files.- Parameters:
parent- the parent to usefiles- the files to obtain the relative path for- Returns:
- the relative paths
-
relativePath
public static String relativePath(File parent, File file)
Returns the part of the file that is relative to the parent. If the file does not start with the parent, it will return the absolute path of the file.- Parameters:
parent- the parent to usefile- the file to obtain the relative path for- Returns:
- the relative path
-
relativePath
public static String[] relativePath(String parent, String[] files)
Returns the part of the files that is relative to the parent. If the files do not start with the parent, it will return the absolute paths of the files.- Parameters:
parent- the parent to usefiles- the files to obtain the relative path for- Returns:
- the relative paths
-
relativePath
public static String relativePath(String parent, String file)
Returns the part of the file that is relative to the parent. If the file does not start with the parent, it will return the absolute path of the file.- Parameters:
parent- the parent to usefile- the file to obtain the relative path for- Returns:
- the relative path
-
absolutePath
public static String[] absolutePath(File[] files)
Returns the absolute paths.- Parameters:
files- the files to get the absolute paths for- Returns:
- the absolute paths
-
-