public class FileUtil extends Object
IOException and output error logs| 限定符和类型 | 方法和说明 |
|---|---|
static void |
close(Closeable closeable)
Close the
Closeable stream |
static void |
copyFolder(String srcPath,
String descPath,
boolean moveSubFolder)
Copy a directory to a new path
|
static void |
cp_R(Path srcPath,
Path descPath)
Copy a directory to a new path
|
static void |
cp_R(Path srcPath,
Path descPath,
boolean moveSubFolder)
Copy a directory to a new path
|
static void |
cp_R(String srcPath,
String descPath)
Copy a directory to a new path
|
static void |
cp_R(String srcPath,
String descPath,
boolean moveSubFolder)
Copy a directory to a new path
|
static void |
cp(File srcFile,
File descFile)
Copy a single file
|
static long |
cp(InputStream source,
OutputStream sink)
Reads all bytes from an input stream and writes them to an output stream.
|
static void |
cp(InputStream is,
Path descFile)
Copy a single file
|
static void |
cp(Path srcPath,
File descFile)
Copy a single file
|
static boolean |
exists(Path path)
Tests whether a file exists.
|
static Path |
getTargetPath(Path targetPath,
String fileName,
String suffix)
获取目标路径,如果已存在相同文件名则会在文件名后追回
(n)以区分,
n从1开始如果已存在(n)则新文件名为(n + 1)
例:目标文件夹已存在a.xlsx和b(5).xlsx两个文件,添加一个名为a.xlsx的文件
因为a.xlsx已存在所以新文件另存为a(1).xlsx,添加一个名为b.xlsx的文件则新文件另存为b(6).xlsx |
static boolean |
isWindows()
Test current OS system is windows family
|
static Path |
mkdir(Path destPath)
Create a directory
|
static Path |
mktmp(String prefix)
Create a temp directory
|
static void |
rm_rf(File root,
boolean rmSelf)
Remove file and sub-files if it is a directory
|
static void |
rm_rf(Path root)
Remove file and sub-files if it a directory
|
static void |
rm(File file)
Delete if exists file
|
static void |
rm(Path path)
Delete if exists file
|
static void |
writeToDisk(org.dom4j.Document doc,
Path path)
Write the
Document to a specify Path
with xml format |
static void |
writeToDiskNoFormat(org.dom4j.Document doc,
Path path)
Write the
Document to a specify Path |
public static void close(Closeable closeable)
Closeable streamcloseable - a closeable streampublic static void rm(Path path)
path - the file path to be deletepublic static void rm(File file)
file - the file to be deletepublic static void rm_rf(Path root)
root - the root pathpublic static void rm_rf(File root, boolean rmSelf)
root - the root pathrmSelf - remove self if truepublic static void cp(Path srcPath, File descFile)
srcPath - the source pathdescFile - the destination filepublic static void cp(File srcFile, File descFile)
srcFile - the source filedescFile - the destination filepublic static void cp(InputStream is, Path descFile)
is - the source input streamdescFile - the destination pathpublic static long cp(InputStream source, OutputStream sink) throws IOException
source - source inputStreamsink - dist outputStreamIOException - if I/O error occur.public static void cp_R(String srcPath, String descPath, boolean moveSubFolder)
srcPath - the source path stringdescPath - the destination path stringmoveSubFolder - need move sub-folderspublic static void cp_R(Path srcPath, Path descPath, boolean moveSubFolder)
srcPath - the source pathdescPath - the destination pathmoveSubFolder - need move sub-folderspublic static void cp_R(String srcPath, String descPath)
srcPath - the source path stringdescPath - the destination path stringpublic static void cp_R(Path srcPath, Path descPath)
srcPath - the source pathdescPath - the destination pathpublic static void copyFolder(String srcPath, String descPath, boolean moveSubFolder)
srcPath - the source path stringdescPath - the destination path stringmoveSubFolder - need move sub-folderspublic static Path mkdir(Path destPath) throws IOException
destPath - the destination directory pathIOException - if I/O error occurpublic static Path mktmp(String prefix) throws IOException
prefix - the directory prefixIOException - if I/O error occurpublic static boolean isWindows()
public static void writeToDisk(org.dom4j.Document doc,
Path path)
throws IOException
Document to a specify Path
with xml formatdoc - the Documentpath - the output pathIOException - if I/O error occurpublic static void writeToDiskNoFormat(org.dom4j.Document doc,
Path path)
throws IOException
Document to a specify Pathdoc - the Documentpath - the output pathIOException - if I/O error occurpublic static boolean exists(Path path)
path - the path to the file to testpublic static Path getTargetPath(Path targetPath, String fileName, String suffix)
(n)以区分,
n从1开始如果已存在(n)则新文件名为(n + 1)
例:目标文件夹已存在a.xlsx和b(5).xlsx两个文件,添加一个名为a.xlsx的文件
因为a.xlsx已存在所以新文件另存为a(1).xlsx,添加一个名为b.xlsx的文件则新文件另存为b(6).xlsx
targetPath - 目标路径,可以是文件或文件夹fileName - 不带后缀的文件名suffix - 文件后缀,如.xlsxCopyright © 2025. All rights reserved.