private List<ExcelModel> readZip(MultipartFile file) {
// TODO 这里使用GBK方式不要使用UTF8
try (ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(file.getInputStream(), "GBK")) {
List<ExcelModel> importExcel = new ArrayList<>();
ArchiveEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
String fileName = zipEntry.getName().toLowerCase(Locale.ROOT);
String fileNameTemp = fileName.toLowerCase(Locale.ROOT);
String fillName = fileName.substring(0, fileName.lastIndexOf("."));
String[] split = fillName.split("/");
String documentName = split[split.length - 1];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = zipInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
//TODO 处理文件
}
}
zipInputStream.close();
return importExcel;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
java解析zip中文乱码问题解决
最新推荐文章于 2026-05-13 14:28:49 发布
该代码段展示了一个方法,用于读取使用GBK编码的ZIP文件中的Excel模型数据。它遍历ZIP输入流,提取每个文件的内容,将其转换为字节数组,并创建InputStream来处理每个单独的Excel文件。
1308

被折叠的 条评论
为什么被折叠?



