public final class IoUtil extends Object
Modifier and Type | Method and Description |
---|---|
static boolean |
compareFileDates(Date date1,
Date date2)
For some reason modification milliseconds for some files are unstable,
use this function to compare file dates ignoring milliseconds.
|
static boolean |
compareFiles(File file1,
File file2)
Compares two files for directories/files synchronization purposes.
|
static void |
copyFile(File src,
File dest)
Copies one file, existing file will be overridden.
|
static void |
copyFolder(File src,
File dest)
Copies folder recursively, existing files will be overridden
|
static void |
copyFolder(File src,
File dest,
boolean recursive)
Copies folder, existing files will be overridden
|
static void |
copyFolder(File src,
File dest,
boolean recursive,
boolean onlyNew)
Copies folder.
|
static void |
copyFolder(File src,
File dest,
boolean recursive,
boolean onlyNew,
FileFilter filter)
Copies folder.
|
static void |
copyStream(InputStream in,
OutputStream out,
int bufferSize)
Copies streams.
|
static boolean |
emptyFolder(File folder)
Recursively deletes whole content of the given folder.
|
static URL |
file2url(File file)
Utility method to convert a
File object to a local URL. |
static InputStream |
getResourceInputStream(URL url)
Opens input stream for given resource.
|
static boolean |
isResourceExists(URL url)
Checks if resource exist and can be opened.
|
static void |
synchronizeFolders(File src,
File dest)
Performs one-way directories synchronization comparing files only,
not folders.
|
static void |
synchronizeFolders(File src,
File dest,
FileFilter filter)
Performs one-way directories synchronization comparing files only,
not folders.
|
static File |
url2file(URL url)
Utility method to convert local URL to a
File object. |
public static void copyFile(File src, File dest) throws IOException
src
- source file to copy FROMdest
- destination file to copy TOIOException
- if any I/O error has occurredpublic static void copyFolder(File src, File dest) throws IOException
src
- source folderdest
- target folderIOException
- if any I/O error has occurredpublic static void copyFolder(File src, File dest, boolean recursive) throws IOException
src
- source folderdest
- target folderrecursive
- if true
, processes folder recursivelyIOException
- if any I/O error has occurredpublic static void copyFolder(File src, File dest, boolean recursive, boolean onlyNew) throws IOException
src
- source folderdest
- target folderrecursive
- if true
, processes folder recursivelyonlyNew
- if true
, target file will be overridden if it
is older than source file onlyIOException
- if any I/O error has occurredpublic static void copyFolder(File src, File dest, boolean recursive, boolean onlyNew, FileFilter filter) throws IOException
src
- source folderdest
- target folderrecursive
- if true
, processes folder recursivelyonlyNew
- if true
, target file will be overridden if it
is older than source file onlyfilter
- file filter, optional, if null
all files will
be copiedIOException
- if any I/O error has occurredpublic static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException
in
- source streamout
- destination streambufferSize
- buffer size to useIOException
- if any I/O error has occurredpublic static boolean emptyFolder(File folder)
folder
- folder to be emptiedtrue
if given folder becomes empty or not existspublic static boolean compareFiles(File file1, File file2)
file1
- one file to comparefile2
- another file to comparetrue
if file names are equal (case sensitive), files
have equal lengths and modification dates (milliseconds ignored)synchronizeFolders(File, File)
,
compareFileDates(Date, Date)
public static boolean compareFileDates(Date date1, Date date2)
date1
- first file modification datedate2
- second file modification datetrue
if files modification dates are equal ignoring
millisecondspublic static void synchronizeFolders(File src, File dest) throws IOException
src
- source folderdest
- target folderIOException
- if any I/O error has occurredsynchronizeFolders(File, File, FileFilter)
,
compareFiles(File, File)
public static void synchronizeFolders(File src, File dest, FileFilter filter) throws IOException
src
- source folderdest
- target folderfilter
- file filter, optional, if null
all files will
be included into synchronization processIOException
- if any I/O error has occurredcompareFiles(File, File)
public static boolean isResourceExists(URL url)
url
- absolute URL which points to a resource to be checkedtrue
if given URL points to an existing resourcepublic static InputStream getResourceInputStream(URL url) throws IOException
url
- resource URLIOException
- if any I/O error has occurredpublic static File url2file(URL url)
File
object.url
- an URLnull
if URL is not
localpublic static URL file2url(File file) throws MalformedURLException
File
object to a local URL.file
- a file objectMalformedURLException
- if file can't be represented as URL for
some reasonCopyright © 2016. All Rights Reserved.