2 qq 33639992 qq_33639992 于 2017.09.15 10:02 提问

windows环境下,使用java解压tar.gz包出现中文乱码

public void unzipOarFile(String outputDirectory) {
FileInputStream fis = null;
ArchiveInputStream in = null;
BufferedInputStream bufferedInputStream = null;
try {
fis = new FileInputStream(zipfileName);
GZIPInputStream is = new GZIPInputStream(new BufferedInputStream(fis));
in = new ArchiveStreamFactory().createArchiveInputStream("tar", is);
bufferedInputStream = new BufferedInputStream(in);
TarArchiveEntry entry = (TarArchiveEntry) in.getNextEntry();
while (entry != null) {
String name = entry.getName();
String[] names = name.split("/");
String fileName = outputDirectory;
for (int i = 0; i < names.length; i++) {
String str = names[i];
fileName = fileName + File.separator + str;
}
if (name.endsWith("/")) {
mkFolder(fileName);
} else {
File file = mkFile(fileName);
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
int b;
while ((b = bufferedInputStream.read()) != -1) {
bufferedOutputStream.write(b);
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
entry = (TarArchiveEntry) in.getNextEntry();
}

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ArchiveException e) {
        e.printStackTrace();
    } finally {
        try {
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.15 10:54
Csdn user default icon
上传中...
上传图片
插入图片