拆分,认证模板导入-解决解压文件下有多个文件夹时读不到orgMkdirs问题
This commit is contained in:
+2
-2
@@ -710,7 +710,7 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
|
||||
}
|
||||
return Result.error(resultMsg);
|
||||
}
|
||||
String path = uploadpath + "/modal/"+filenameorg;
|
||||
String path = uploadpath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
|
||||
File saveDirectory = new File(path);
|
||||
if(!saveDirectory.isDirectory()){
|
||||
saveDirectory.mkdir();
|
||||
@@ -718,7 +718,7 @@ public class ParamsInfoEOServiceImpl extends ServiceImpl<ParamsInfoEOMapper, Par
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path +File.separator+ file.getOriginalFilename()));
|
||||
try{
|
||||
//解压缩
|
||||
String zipEntryName = FileUnZip.unZipFiles(path +File.separator+ file.getOriginalFilename(),path);
|
||||
String zipEntryName = FileUnZip.unZipFiles2(path +File.separator+ file.getOriginalFilename(),path);
|
||||
// 数据相关处理,
|
||||
// 1.获取其中的Excel,
|
||||
List<File> excelfilelist = FileUnZip.readExcelFile(zipEntryName);
|
||||
|
||||
+49
@@ -76,6 +76,55 @@ public class FileUnZip {
|
||||
return orgMkdirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压zip文件
|
||||
* 解决解压文件下有多个文件夹时,读不到orgMkdirs问题
|
||||
* @param sourceFile,待解压的zip文件; descDir,解压后的存放路径
|
||||
* @throws Exception
|
||||
* @author gaoyan
|
||||
**/
|
||||
public static String unZipFiles2(String sourceFile, String descDir) throws IOException {
|
||||
File zipFile = new File(sourceFile);
|
||||
|
||||
File pathFile = new File(descDir);
|
||||
if (!pathFile.exists()) {
|
||||
pathFile.mkdirs();
|
||||
}
|
||||
ZipFile zip = new ZipFile(zipFile,"gbk");
|
||||
String orgMkdirsLast = "";
|
||||
for (Enumeration entries = zip.getEntries(); entries.hasMoreElements(); ) {
|
||||
ZipEntry entry = (ZipEntry) entries.nextElement();
|
||||
String zipEntryName = entry.getName();
|
||||
String outPath = (descDir + "/" + zipEntryName).replaceAll("\\*", "/");
|
||||
orgMkdirsLast = zipEntryName.substring(0, zipEntryName.indexOf('/'));
|
||||
//判断路径是否存在,不存在则创建文件路径
|
||||
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
|
||||
if (new File(outPath).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
//输出文件路径信息
|
||||
// InputStream in = null;
|
||||
// OutputStream out = null;
|
||||
try(InputStream in =zip.getInputStream(entry);
|
||||
OutputStream out =new FileOutputStream(outPath)){
|
||||
byte[] buf1 = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf1)) > 0) {
|
||||
out.write(buf1, 0, len);
|
||||
}
|
||||
}catch(IOException e){
|
||||
logger.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
zip.close();
|
||||
String orgMkdirs = descDir + "/" + orgMkdirsLast;
|
||||
return orgMkdirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除文件及文件夹
|
||||
*
|
||||
|
||||
+2
-2
@@ -1484,7 +1484,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
}
|
||||
return Result.error(resultMsg);
|
||||
}
|
||||
String path = uploadpath + "/modal/"+filenameorg;
|
||||
String path = uploadpath + File.separator + "modal" + File.separator + filenameorg + System.currentTimeMillis();
|
||||
File saveDirectory = new File(path);
|
||||
if(!saveDirectory.isDirectory()){
|
||||
saveDirectory.mkdir();
|
||||
@@ -1492,7 +1492,7 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path +File.separator+ file.getOriginalFilename()));
|
||||
try{
|
||||
//解压缩
|
||||
String zipEntryName = FileUnZip.unZipFiles(path +File.separator+ file.getOriginalFilename(),path);
|
||||
String zipEntryName = FileUnZip.unZipFiles2(path +File.separator+ file.getOriginalFilename(),path);
|
||||
// 数据相关处理,
|
||||
// 1.获取其中的Excel,
|
||||
List<File> excelfilelist = FileUnZip.readExcelFile(zipEntryName);
|
||||
|
||||
Reference in New Issue
Block a user