From 881015b3526c62f8654572dbbbbc0374accdf97d Mon Sep 17 00:00:00 2001 From: tw108174 Date: Mon, 20 May 2019 11:14:22 +0800 Subject: [PATCH] java sdk ziputils fix --- src/main/java/com/aliyuncs/fc/utils/ZipUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/aliyuncs/fc/utils/ZipUtils.java b/src/main/java/com/aliyuncs/fc/utils/ZipUtils.java index b4249ad..eeaceb4 100644 --- a/src/main/java/com/aliyuncs/fc/utils/ZipUtils.java +++ b/src/main/java/com/aliyuncs/fc/utils/ZipUtils.java @@ -28,8 +28,11 @@ public static void zipDir(File dir, String zipName) throws IOException { ZipOutputStream zos = new ZipOutputStream(fos); for (String filePath : fileNames) { // for ZipEntry we need to keep only relative file path, so we used substring on absolute path - ZipEntry ze = new ZipEntry( - filePath.substring(dir.getAbsolutePath().length() + 1, filePath.length())); + String zipFilePath = filePath.substring(dir.getAbsolutePath().length() + 1, filePath.length()); + if (File.separatorChar != '/') { + zipFilePath = zipFilePath.replace("\\", "/"); + } + ZipEntry ze = new ZipEntry(zipFilePath); zos.putNextEntry(ze); // read the file and write to ZipOutputStream FileInputStream fis = new FileInputStream(filePath);