public final class IoUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
compareFileDates(java.util.Date date1,
java.util.Date date2)
For some reason modification milliseconds for some files are unstable,
use this function to compare file dates ignoring milliseconds.
|
static boolean |
compareFiles(java.io.File file1,
java.io.File file2)
Compares two files for directories/files synchronization purposes.
|
static void |
copyFile(java.io.File src,
java.io.File dest)
Copies one file, existing file will be overridden.
|
static void |
copyFolder(java.io.File src,
java.io.File dest)
Copies folder recursively, existing files will be overridden
|
static void |
copyFolder(java.io.File src,
java.io.File dest,
boolean recursive)
Copies folder, existing files will be overridden
|
static void |
copyFolder(java.io.File src,
java.io.File dest,
boolean recursive,
boolean onlyNew)
Copies folder.
|
static void |
copyFolder(java.io.File src,
java.io.File dest,
boolean recursive,
boolean onlyNew,
java.io.FileFilter filter)
Copies folder.
|
static void |
copyStream(java.io.InputStream in,
java.io.OutputStream out,
int bufferSize)
Copies streams.
|
static boolean |
emptyFolder(java.io.File folder)
Recursively deletes whole content of the given folder.
|
static java.net.URL |
file2url(java.io.File file)
Utility method to convert a
File object to a local URL. |
static java.io.InputStream |
getResourceInputStream(java.net.URL url)
Opens input stream for given resource.
|
static boolean |
isResourceExists(java.net.URL url)
Checks if resource exist and can be opened.
|
static void |
synchronizeFolders(java.io.File src,
java.io.File dest)
Performs one-way directories synchronization comparing files only,
not folders.
|
static void |
synchronizeFolders(java.io.File src,
java.io.File dest,
java.io.FileFilter filter)
Performs one-way directories synchronization comparing files only,
not folders.
|
static java.io.File |
url2file(java.net.URL url)
Utility method to convert local URL to a
File object. |
public static void copyFile(java.io.File src,
java.io.File dest)
throws java.io.IOException
src - source file to copy FROMdest - destination file to copy TOjava.io.IOException - if any I/O error has occurredpublic static void copyFolder(java.io.File src,
java.io.File dest)
throws java.io.IOException
src - source folderdest - target folderjava.io.IOException - if any I/O error has occurredpublic static void copyFolder(java.io.File src,
java.io.File dest,
boolean recursive)
throws java.io.IOException
src - source folderdest - target folderrecursive - if true, processes folder recursivelyjava.io.IOException - if any I/O error has occurredpublic static void copyFolder(java.io.File src,
java.io.File dest,
boolean recursive,
boolean onlyNew)
throws java.io.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 onlyjava.io.IOException - if any I/O error has occurredpublic static void copyFolder(java.io.File src,
java.io.File dest,
boolean recursive,
boolean onlyNew,
java.io.FileFilter filter)
throws java.io.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 copiedjava.io.IOException - if any I/O error has occurredpublic static void copyStream(java.io.InputStream in,
java.io.OutputStream out,
int bufferSize)
throws java.io.IOException
in - source streamout - destination streambufferSize - buffer size to usejava.io.IOException - if any I/O error has occurredpublic static boolean emptyFolder(java.io.File folder)
folder - folder to be emptiedtrue if given folder becomes empty or not existspublic static boolean compareFiles(java.io.File file1,
java.io.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(java.util.Date date1,
java.util.Date date2)
date1 - first file modification datedate2 - second file modification datetrue if files modification dates are equal ignoring
millisecondspublic static void synchronizeFolders(java.io.File src,
java.io.File dest)
throws java.io.IOException
src - source folderdest - target folderjava.io.IOException - if any I/O error has occurredsynchronizeFolders(File, File, FileFilter),
compareFiles(File, File)public static void synchronizeFolders(java.io.File src,
java.io.File dest,
java.io.FileFilter filter)
throws java.io.IOException
src - source folderdest - target folderfilter - file filter, optional, if null all files will
be included into synchronization processjava.io.IOException - if any I/O error has occurredcompareFiles(File, File)public static boolean isResourceExists(java.net.URL url)
url - absolute URL which points to a resource to be checkedtrue if given URL points to an existing resourcepublic static java.io.InputStream getResourceInputStream(java.net.URL url)
throws java.io.IOException
url - resource URLjava.io.IOException - if any I/O error has occurredpublic static java.io.File url2file(java.net.URL url)
File object.url - an URLnull if URL is not
localpublic static java.net.URL file2url(java.io.File file)
throws java.net.MalformedURLException
File object to a local URL.file - a file objectjava.net.MalformedURLException - if file can't be represented as URL for
some reasonCopyright © 2004-2007 Dmitry Olshansky. All Rights Reserved.