@Immutable public class FileUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
addFileToZip(String path,
String srcFile,
ZipOutputStream zip,
boolean flag)
Appends file to the archive.
|
static void |
addFolderToZip(String path,
String srcFolder,
ZipOutputStream zip)
Adds folder to the archive.
|
static URL |
convertFileToURL(String filePath)
|
static int |
copy(File sourceFileOrDirectory,
File destinationFileOrDirectory)
Copy the source file system structure into the supplied target location.
|
static int |
copy(File sourceFileOrDirectory,
File destinationFileOrDirectory,
FilenameFilter exclusionFilter)
Copy the source file system structure into the supplied target location.
|
static boolean |
delete(File fileOrDirectory)
Delete the file or directory given by the supplied reference.
|
static boolean |
delete(String path)
Delete the file or directory at the supplied path.
|
static String |
getExtension(String filename)
Returns the extension of a file, including the dot.
|
static long |
size(String filePath)
Determines the size (in bytes) of the file or directory at the given path.
|
static void |
unzip(InputStream zipFile,
String dest)
Unzip archive to the specified destination.
|
static void |
zipDir(String dirName,
String nameZipFile)
Compresses directory into zip archive.
|
public static boolean delete(String path)
File.delete() method.path - the path to the file or directory that is to be deletedpublic static boolean delete(File fileOrDirectory)
File.delete() method.fileOrDirectory - the reference to the Java File object that is to be deletedpublic static int copy(File sourceFileOrDirectory, File destinationFileOrDirectory) throws IOException
sourceFileOrDirectory - the file or directory whose contents are to be copied into the target locationdestinationFileOrDirectory - the location where the copy is to be placed; does not need to exist, but if it does its
type must match that of srcIllegalArgumentException - if the src or dest references are nullIOExceptionpublic static int copy(File sourceFileOrDirectory, File destinationFileOrDirectory, FilenameFilter exclusionFilter) throws IOException
sourceFileOrDirectory - the file or directory whose contents are to be copied into the target locationdestinationFileOrDirectory - the location where the copy is to be placed; does not need to exist, but if it does its
type must match that of srcexclusionFilter - a filter that matches files or folders that should _not_ be copied; null indicates that all files
and folders should be copiedIllegalArgumentException - if the src or dest references are nullIOExceptionpublic static URL convertFileToURL(String filePath) throws MalformedURLException
filePath - the path of the fileURL representation of the file.MalformedURLExceptionIllegalArgumentException - if the file path is null, empty or blankpublic static long size(String filePath) throws IOException
filePath - the path of the file; may not be nullIOException - if anything unexpected fails.public static void unzip(InputStream zipFile, String dest) throws IOException
zipFile - zip archivedest - directory where archive will be uncompressedIOExceptionpublic static void zipDir(String dirName, String nameZipFile) throws IOException
dirName - the path to the directorynameZipFile - archive name.IOExceptionpublic static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException
path - path to the foldersrcFolder - folder namezip - zip archiveIOExceptionpublic static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException
path - path to the filesrcFile - file namezip - archiveflag - IOExceptionpublic static String getExtension(String filename)
filename - the name of a file, may be not be nullCopyright © 2008–2021 JBoss, a division of Red Hat. All rights reserved.