public class ZipUtils
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
protected static org.apache.commons.logging.Log |
log |
构造器和说明 |
---|
ZipUtils() |
限定符和类型 | 方法和说明 |
---|---|
static void |
compress(java.nio.file.Path sourceFilePath,
org.apache.tools.zip.ZipOutputStream out,
java.lang.String basedir) |
static void |
compressFile(java.io.File file,
org.apache.tools.zip.ZipOutputStream out,
java.lang.String fullName)
@RequestMapping("export")
public void export(javax.servlet.http.HttpServletResponse response) {
try (ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream())) {
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("filename.zip", "utf-8"));
ZipUtils.compressFile(new File("filename.txt"), zipOutputStream, "dir/filename.txt");
} catch (IOException e) {
}
}
|
static void |
compressFile(java.io.InputStream inputStream,
org.apache.tools.zip.ZipOutputStream out,
java.lang.String fullName) |
static void |
unzip(java.lang.String zipFilePath,
java.lang.String encoding,
boolean overwrite) |
static void |
unzip(java.lang.String zipFilePath,
java.lang.String targetPath,
java.lang.String encoding,
boolean overwrite) |
static void |
unzip(org.apache.tools.zip.ZipFile zipFile,
java.lang.String directory,
java.lang.String targetPath,
boolean overwrite) |
private static void |
unzip(org.apache.tools.zip.ZipFile zipFile,
org.apache.tools.zip.ZipEntry zipEntry,
java.lang.String targetPath,
java.lang.String filePath,
boolean overwrite) |
static void |
unzipHere(java.lang.String zipFilePath,
java.lang.String encoding,
boolean overwrite) |
static boolean |
zip(java.lang.String sourceFilePath,
java.lang.String zipFilePath) |
static boolean |
zip(java.lang.String sourceFilePath,
java.lang.String zipFilePath,
boolean overwrite) |
public static boolean zip(java.lang.String sourceFilePath, java.lang.String zipFilePath) throws java.io.IOException
sourceFilePath
- zipFilePath
- java.io.IOException
public static boolean zip(java.lang.String sourceFilePath, java.lang.String zipFilePath, boolean overwrite) throws java.io.IOException
sourceFilePath
- zipFilePath
- overwrite
- java.io.IOException
public static void compress(java.nio.file.Path sourceFilePath, org.apache.tools.zip.ZipOutputStream out, java.lang.String basedir) throws java.io.IOException
sourceFilePath
- out
- basedir
- java.io.IOException
public static void compressFile(java.io.File file, org.apache.tools.zip.ZipOutputStream out, java.lang.String fullName) throws java.io.IOException
@RequestMapping("export") public void export(javax.servlet.http.HttpServletResponse response) { try (ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream())) { response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("filename.zip", "utf-8")); ZipUtils.compressFile(new File("filename.txt"), zipOutputStream, "dir/filename.txt"); } catch (IOException e) { } }
file
- out
- fullName
- java.io.IOException
public static void compressFile(java.io.InputStream inputStream, org.apache.tools.zip.ZipOutputStream out, java.lang.String fullName) throws java.io.IOException
java.io.IOException
public static void unzipHere(java.lang.String zipFilePath, java.lang.String encoding, boolean overwrite) throws java.io.IOException
zipFilePath
- encoding
- overwrite
- java.io.IOException
public static void unzip(java.lang.String zipFilePath, java.lang.String encoding, boolean overwrite) throws java.io.IOException
zipFilePath
- encoding
- overwrite
- java.io.IOException
public static void unzip(java.lang.String zipFilePath, java.lang.String targetPath, java.lang.String encoding, boolean overwrite) throws java.io.IOException
zipFilePath
- targetPath
- encoding
- overwrite
- java.io.IOException
private static void unzip(org.apache.tools.zip.ZipFile zipFile, org.apache.tools.zip.ZipEntry zipEntry, java.lang.String targetPath, java.lang.String filePath, boolean overwrite)
public static void unzip(org.apache.tools.zip.ZipFile zipFile, java.lang.String directory, java.lang.String targetPath, boolean overwrite)