@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 src
IllegalArgumentException
- if the src
or dest
references are nullIOException
public 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 src
exclusionFilter
- 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 nullIOException
public static URL convertFileToURL(String filePath) throws MalformedURLException
filePath
- the path of the fileURL
representation of the file.MalformedURLException
IllegalArgumentException
- 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 null
IOException
- if anything unexpected fails.public static void unzip(InputStream zipFile, String dest) throws IOException
zipFile
- zip archivedest
- directory where archive will be uncompressedIOException
public static void zipDir(String dirName, String nameZipFile) throws IOException
dirName
- the path to the directorynameZipFile
- archive name.IOException
public static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException
path
- path to the foldersrcFolder
- folder namezip
- zip archiveIOException
public static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException
path
- path to the filesrcFile
- file namezip
- archiveflag
- IOException
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.