@StableMinor(version="12.4", sinceVersion="4.0") public class FileUtil extends Object
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
compareFiles(File file1,
File file2)
Compare two files.
|
static boolean |
compareStream(InputStream in1,
InputStream in2) |
static void |
copyDir(File srcDir,
File destDir)
Copies the source folder recursively to the destination folder.
|
static void |
copyFile(File srcFile,
File destFile)
Copies a file.
|
static void |
copyStream(InputStream in,
OutputStream out) |
static File |
createDir(String dirPath,
boolean clearIfExists) |
static File |
createFile(String filePath) |
static FileOutputStream |
createFileOutputStream(String filePath) |
static void |
createParentDirectories(File file)
Creates the directories parent of the given file.
|
static boolean |
deleteDir(File dir) |
static boolean |
deleteDir(File dir,
boolean deleteFiles) |
static boolean |
deleteDir(String dir) |
static boolean |
deleteDir(String dir,
boolean deleteFiles) |
static boolean |
deleteFile(File file)
Deletes the given file.
|
static boolean |
deleteFile(String filePath) |
static void |
extractZip(InputStream inputStream,
File destDir)
Extracts an input stream in ZIP format to the file system.
|
static void |
extractZip(InputStream inputStream,
IFile destDir)
Extracts an input stream in ZIP format to the file system.
|
static void |
extractZip(ZipInputStream zipInput,
File destDir)
Deprecated.
Since 7.0.0, replaced by
extractZip(InputStream, File) due to limitations in Java's
embedded java.util.zip package on working with different zip entry
names encodings. |
static boolean |
fileExists(String filePath) |
static String |
getFileExtension(String fileName)
Returns the extension of given file.
|
static boolean |
move(String sourcePath,
String targetPath) |
static byte[] |
readFile(File file)
Returns the content of a file as an array of bytes.
|
static void |
zipDir(File dirToZip,
String dirZipRelativePath,
ZipOutputStream zos)
Zips a directory recursively into the given zip output stream.
|
static void |
zipDir(File dirToZip,
ZipOutputStream zos)
Zips a directory recursively into the given zip output stream.
|
static void |
zipDir(IFile dirToZip,
String dirZipRelativePath,
ZipOutputStream zos)
Zips a directory recursively into the given zip output stream.
|
static void |
zipDir(IFile dirToZip,
ZipOutputStream zos)
Zips a directory recursively into the given zip output stream.
|
public static FileOutputStream createFileOutputStream(String filePath) throws PortalException
PortalException
public static File createDir(String dirPath, boolean clearIfExists) throws PortalException
PortalException
public static File createFile(String filePath) throws PortalException
PortalException
public static boolean fileExists(String filePath)
public static boolean deleteDir(String dir)
public static boolean deleteFile(String filePath)
public static boolean deleteFile(File file)
file
- the file to be deleted.IllegalArgumentException
- if the given argument is a directory.public static boolean deleteDir(String dir, boolean deleteFiles)
public static boolean deleteDir(File dir)
public static boolean deleteDir(File dir, boolean deleteFiles)
public static void copyDir(File srcDir, File destDir) throws IOException
srcDir
- the source folderdestDir
- the destination folder.IOException
- if any error occurs during the read or write file.public static void copyFile(File srcFile, File destFile) throws IOException
IOException
- if an I/O error occurs.public static void copyStream(InputStream in, OutputStream out) throws IOException
IOException
public static boolean compareFiles(File file1, File file2) throws IOException
file1
- file2
- IOException
public static boolean compareStream(InputStream in1, InputStream in2) throws IOException
IOException
@Deprecated public static void extractZip(ZipInputStream zipInput, File destDir) throws IOException
extractZip(InputStream, File)
due to limitations in Java's
embedded java.util.zip package on working with different zip entry
names encodings.zipInput
- the zip input stream.destDir
- the directory where the zip is to be extracted.IOException
- if an I/O error occurs.public static void extractZip(InputStream inputStream, File destDir) throws IOException
inputStream
- the input stream. This is expected to be the raw
input stream of the bytes in ZIP format, and must not be an input stream
that already does the ZIP uncompressing such as ZipInputStream
.destDir
- the file system directory where the ZIP contents are
to be extracted to.IOException
- if an I/O error occurred while reading the input
stream or writing to the file system.public static void extractZip(InputStream inputStream, IFile destDir) throws IOException
inputStream
- the input stream. This is expected to be the raw input stream of the bytes in ZIP format, and
must not be an input stream that already does the ZIP uncompressing such as ZipInputStream
.destDir
- the file system directory where the ZIP contents are to be extracted to.IOException
- if an I/O error occurred while reading the input stream or writing to the file system.public static void zipDir(File dirToZip, ZipOutputStream zos) throws IOException
dirToZip
- the dir to zip.zos
- the zip output stream.IOException
- if an I/O error occurs.public static void zipDir(File dirToZip, String dirZipRelativePath, ZipOutputStream zos) throws IOException
dirToZip
- the dir to zip.dirZipRelativePath
- the path for the dir inside the generated zip
file. If it refers to the zip root, its value must be an empty string;
or it must end with slash if it refers to a directory inside the zip.zos
- the zip output stream.IOException
- if an I/O error occurs.public static void zipDir(IFile dirToZip, ZipOutputStream zos) throws IOException
dirToZip
- the dir to zip.zos
- the zip output stream.IOException
- if an I/O error occurs.public static void zipDir(IFile dirToZip, String dirZipRelativePath, ZipOutputStream zos) throws IOException
dirToZip
- the dir to zip.dirZipRelativePath
- the path for the dir inside the generated zip file. If it refers to the zip root, its value must be an
empty string; or it must end with slash if it refers to a directory inside the zip.zos
- the zip output stream.IOException
- if an I/O error occurs.public static void createParentDirectories(File file) throws IOException
file
- the file.IOException
- if it was not possible to create the directories.public static byte[] readFile(File file) throws IOException
file
- the file.IOException
- if an I/O error occurs.LumisXP 12.4.0.200625 - Copyright © 2006–2020 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.