哪位大侠知道 window压缩 linux解压缩 java程序解压缩出来的文件带%5C是怎么回事?
我用的压缩代码是:
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFileName)));
out.setEncoding("UTF-8");
String base = null;
if (inputFile.isDirectory()) {
ZipEntry entry = new
ZipEntry(getZipEntryName(inputFile.getPath(), null) + "/");
private void zipData(ZipOutputStream out, File file, String base)
throws
FileNotFoundException,
IOException {
FileInputStream in = null;
try {
log.debug("zipData start");
if (file.isDirectory()) {
// アップロードフォルダの场合
File[] fl = file.listFiles();
out.putNextEntry(new ZipEntry(getZipEntryName(file.getPath(), base) +
"/"));
base = base.length() == 0 ? "" : base + "/";
for (int i = 0; i < fl.length; i++) {
zipData(out, fl[i], base);
}
} else if (file.isFile()) {
// 次の圧缩ノードを生成するために
out.putNextEntry(new ZipEntry(getZipEntryName(file.getPath(), base)));
byte[] byteB = new byte[1024];
in = new FileInputStream(file);
int b;
while ((b = in.read(byteB, 0, byteB.length)) != -1) {
out.write(byteB, 0, b);
}
}
解压缩代码是
zipFile = new ZipFile(localPath);
Enumeration<ZipEntry> enumeration = (Enumeration<ZipEntry>) zipFile.getEntries();
while (enumeration.hasMoreElements()) {
ZipEntry entry = enumeration.nextElement();
String fileName = destFilePath + File.separator + entry.getName();
if (entry.isDirectory()) {
FileUtils.forceMkdir(new File(fileName));
} else {
log.debug("file decompress -> " + entry.getName());
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
try {
File parent =
new File(fileName).getParentFile();
if (parent != null) {
FileUtils.forceMkdir(parent);
}
bos = new BufferedOutputStream(new FileOutputStream(fileName));
bis = new BufferedInputStream(zipFile.getInputStream(entry));
byte[] buf = new byte[1024];
int size = 0;
while ((size = bis.read(buf)) != -1) {
bos.write(buf, 0, size);
}
} finally {
CloseableUtils.close(bos, bis);
}
}
}
解压缩出的文件 把每个文件上带的路径的分隔符都直接写成%5C
例如应该是 BARTAR\1\3.txt
现在是 BARTAR%5C1%5C3.txt
这是怎么回事?
怎么解决?
------解决方案--------------------
%5C是斜杠的编码,弄弄编码设置,看看效果