public class IoUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_SEPARATOR
Default separator for tabular files.
|
static String |
ENCODING
Default encoding, cf the second rule.
|
Constructor and Description |
---|
IoUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
append(File in,
File out)
Appends the content of a file to another.
|
static String |
appendSuffix(String fileName,
String suffix)
Appends a suffix to a file name before the file extension.
|
static boolean |
checkIfURLExists(String targetUrlAsString,
String userName,
String password)
Check if a given URL exists.
|
static void |
closeBuffer(MappedByteBuffer buffer)
Attempts at closing a buffer.
|
static void |
copyFile(File in,
File out)
Copy the content of a file to another.
|
static void |
copyFile(File in,
File out,
boolean overwrite)
Copy the content of one file to another.
|
static boolean |
deleteDir(File dir)
Deletes all files and subdirectories under dir and dir itself.
|
static boolean |
emptyDir(File dir)
Deletes all files and subdirectories under dir.
|
static File |
existsExtensionNotCaseSensitive(File file)
Checks if the given file exists with the extension in another case and
returns it.
|
static String |
getExtension(File file)
Returns the extensions of a file.
|
static String |
getExtension(String fileName)
Returns the extensions of a file name.
|
static String |
getFileName(File file)
An OS independent getName alternative.
|
static String |
getFileName(String filePath)
An OS independent getName alternative.
|
static String |
getFilenameExtensionLowerCase(String fileName)
Returns the given file name with lower-case extension.
|
static int |
getFileSize(URL url)
Returns the size of the file located at the given URL.
|
static String |
removeExtension(String fileName)
Removes the extension from a file name or path.
|
static File |
saveUrl(File saveFile,
String targetUrlAsString,
int fileSizeInBytes,
String userName,
String password,
WaitingHandler waitingHandler)
Save a file from a URL.
|
public static final String ENCODING
public static final String DEFAULT_SEPARATOR
public static boolean emptyDir(File dir)
dir
- the directory to deletepublic static boolean deleteDir(File dir)
dir
- the directory to deletepublic static void copyFile(File in, File out) throws IOException
in
- the file to copy fromout
- the file to copy toIOException
- if a problem occurs when writing to the filepublic static void append(File in, File out) throws IOException
in
- the file to copy fromout
- the file to copy toIOException
- if a problem occurs when writing to the filepublic static void copyFile(File in, File out, boolean overwrite) throws IOException
in
- the file to copy fromout
- the file to copy tooverwrite
- boolean indicating whether out should be overwrittenIOException
- if an error occurred while reading or writing a filepublic static String getFileName(String filePath)
filePath
- the file path as a stringpublic static String getFileName(File file)
file
- the filepublic static String getExtension(File file)
file
- the filepublic static String getExtension(String fileName)
fileName
- The file name.public static String getFilenameExtensionLowerCase(String fileName)
fileName
- The name of the file.public static File existsExtensionNotCaseSensitive(File file)
file
- The file to check.public static String appendSuffix(String fileName, String suffix)
fileName
- the file namesuffix
- the suffix to addpublic static String removeExtension(String fileName)
fileName
- the file namepublic static File saveUrl(File saveFile, String targetUrlAsString, int fileSizeInBytes, String userName, String password, WaitingHandler waitingHandler) throws MalformedURLException, IOException, FileNotFoundException
saveFile
- the file to save totargetUrlAsString
- the target URL as a stringfileSizeInBytes
- the file size in bytesuserName
- the user namepassword
- the passwordwaitingHandler
- the waiting handlerMalformedURLException
- thrown if an MalformedURLException occursIOException
- thrown if an IOException occursFileNotFoundException
- thrown if a FileNotFoundException occurspublic static boolean checkIfURLExists(String targetUrlAsString, String userName, String password)
targetUrlAsString
- the URL to checkuserName
- the user namepassword
- the passwordpublic static int getFileSize(URL url)
url
- the url of the filepublic static void closeBuffer(MappedByteBuffer buffer)
buffer
- the buffer to closeCopyright © 2021. All rights reserved.