|
@@ -39,9 +39,14 @@ public class FileUtil {
|
|
public static void cpR(String sourceDirectoryPath, String targetDirectoryPath) {
|
|
public static void cpR(String sourceDirectoryPath, String targetDirectoryPath) {
|
|
File[] files = new File(sourceDirectoryPath).listFiles();
|
|
File[] files = new File(sourceDirectoryPath).listFiles();
|
|
for (File file : files) {
|
|
for (File file : files) {
|
|
- String sourceFilePath = file.getAbsolutePath();
|
|
|
|
- String targetFilePath = sourceFilePath.replace(sourceDirectoryPath, targetDirectoryPath);
|
|
|
|
- cp(sourceFilePath, targetFilePath);
|
|
|
|
|
|
+ if (file.isDirectory()) {
|
|
|
|
+ file.mkdir();
|
|
|
|
+ }
|
|
|
|
+ if (file.isFile()) {
|
|
|
|
+ String sourceFilePath = file.getAbsolutePath();
|
|
|
|
+ String targetFilePath = sourceFilePath.replace(sourceDirectoryPath, targetDirectoryPath);
|
|
|
|
+ cp(sourceFilePath, targetFilePath);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -104,24 +109,25 @@ public class FileUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取当前目录下的一级文件全路径列表
|
|
* 获取当前目录下的一级文件全路径列表
|
|
|
|
+ *
|
|
* @param path 根路径
|
|
* @param path 根路径
|
|
* @return 文件全路径列表
|
|
* @return 文件全路径列表
|
|
*/
|
|
*/
|
|
public static List<String> ls(String path) {
|
|
public static List<String> ls(String path) {
|
|
File[] files = new File(path).listFiles();
|
|
File[] files = new File(path).listFiles();
|
|
- if (files == null){
|
|
|
|
|
|
+ if (files == null) {
|
|
throw new RuntimeException("路径不存在!");
|
|
throw new RuntimeException("路径不存在!");
|
|
}
|
|
}
|
|
List<String> result = new ArrayList<>();
|
|
List<String> result = new ArrayList<>();
|
|
for (File file : files) {
|
|
for (File file : files) {
|
|
- result.add(file.getAbsolutePath()) ;
|
|
|
|
|
|
+ result.add(file.getAbsolutePath());
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
- public static String read(String path){
|
|
|
|
|
|
+ public static String read(String path) {
|
|
return read(getFile(path));
|
|
return read(getFile(path));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -415,7 +421,7 @@ public class FileUtil {
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
- if (".tar.gz".equals(fileType)|| ".tgz".equals(fileType)|| ".gz".equals(fileType)) {
|
|
|
|
|
|
+ if (".tar.gz".equals(fileType) || ".tgz".equals(fileType) || ".gz".equals(fileType)) {
|
|
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream((new GzipCompressorInputStream(inputStream)));
|
|
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream((new GzipCompressorInputStream(inputStream)));
|
|
TarArchiveEntry entry;
|
|
TarArchiveEntry entry;
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
@@ -443,6 +449,7 @@ public class FileUtil {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 扫描压缩包中是否存在指定文件
|
|
* 扫描压缩包中是否存在指定文件
|
|
|
|
+ *
|
|
* @param inputStream
|
|
* @param inputStream
|
|
* @param fileType
|
|
* @param fileType
|
|
* @return
|
|
* @return
|
|
@@ -454,17 +461,17 @@ public class FileUtil {
|
|
TarArchiveEntry entry;
|
|
TarArchiveEntry entry;
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
|
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
|
- if (entry.getName().contains(targetFileName)){
|
|
|
|
|
|
+ if (entry.getName().contains(targetFileName)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (".tar.gz".equals(fileType)|| ".tgz".equals(fileType)|| ".gz".equals(fileType)) {
|
|
|
|
|
|
+ if (".tar.gz".equals(fileType) || ".tgz".equals(fileType) || ".gz".equals(fileType)) {
|
|
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream((new GzipCompressorInputStream(inputStream)));
|
|
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream((new GzipCompressorInputStream(inputStream)));
|
|
TarArchiveEntry entry;
|
|
TarArchiveEntry entry;
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
// 将 tar 文件解压到 extractPath 目录下
|
|
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
|
while ((entry = tarArchiveInputStream.getNextTarEntry()) != null) {
|
|
- if (entry.getName().contains(targetFileName)){
|
|
|
|
|
|
+ if (entry.getName().contains(targetFileName)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -626,13 +633,13 @@ public class FileUtil {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- public static void deleteFileBySubstring(String parentDirectoryPath,String substringOfFilename){
|
|
|
|
|
|
+ public static void deleteFileBySubstring(String parentDirectoryPath, String substringOfFilename) {
|
|
File[] files = new File(parentDirectoryPath).listFiles();
|
|
File[] files = new File(parentDirectoryPath).listFiles();
|
|
- if(files == null || files.length == 0){
|
|
|
|
|
|
+ if (files == null || files.length == 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
for (File file : files) {
|
|
for (File file : files) {
|
|
- if (file.getName().contains(substringOfFilename)){
|
|
|
|
|
|
+ if (file.getName().contains(substringOfFilename)) {
|
|
boolean delete = file.delete();
|
|
boolean delete = file.delete();
|
|
}
|
|
}
|
|
}
|
|
}
|