首页 > 代码库 > java 解压缩 中文名称问题
java 解压缩 中文名称问题
public List<String> unZip(String pathString, String zipPathString) {
long startTime = System.currentTimeMillis();
List<String> list = new ArrayList<>();
try {
Charset charset = Charset.forName("GBK");
ZipInputStream Zin = new ZipInputStream(new FileInputStream(
zipPathString), charset);// 输入源zip路径
BufferedInputStream Bin = new BufferedInputStream(Zin);
String Parent = pathString; // 输出路径(文件夹目录)
File Fout = null;
ZipEntry entry;
// List<ImgItem> list = new ArrayList<ImgItem>();
try {
while ((entry = Zin.getNextEntry()) != null
&& !entry.isDirectory()) {
String filenameString = entry.getName();
list.add(filenameString);
Fout = new File(Parent, filenameString);
if (!Fout.exists()) {
(new File(Fout.getParent())).mkdirs();
}
FileOutputStream out = new FileOutputStream(Fout);
BufferedOutputStream Bout = new BufferedOutputStream(out);
int b;
while ((b = Bin.read()) != -1) {
Bout.write(b);
}
Bout.close();
out.close();
System.out.println(Fout + "解压成功");
}
Bin.close();
Zin.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println("耗费时间: " + (endTime - startTime) + " ms");
return list;
}
java 解压缩 中文名称问题