How to zip files from my result?
我需要知道如何压缩从结果中获得的文件,我文件夹中的所有文件都比 1 月 30 日旧,我需要压缩它们,我该怎么办??
请看代码:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
package agefilefilter;
import java.io.File; import org.apache.commons.io.filefilter.AgeFileFilter; public class AgeFileFilterTest { public static void main(String[] args) throws IOException { File directory = new File(“C:\\\\Users\\\\kroon_000\\\\Desktop\\\\files”); GregorianCalendar cal = new GregorianCalendar();
System.out.println(“\ } public static void displayFiles(File directory, FileFilter fileFilter) { } |
结果:
1
2 3 4 5 6 |
Before Thu Jan 30 00:00:00 CAT 2014
File: 2014–01–12–17–37–28–11304–Processed_INST–11304–20140112–120140112.zip, Date: Sun Jan 12 17:37:29 CAT 2014 File: Bill Issuer Summary – 2014–01–23 to 2014–01–23.pdf, Date: Fri Jan 24 02:18:39 CAT 2014 File: Cape Agulhas Settlement for 2013–12–02 to 2013–12–02.csv, Date: Tue Dec 03 09:24:06 CAT 2013 File: Cape Agulhas Settlement for 2013–12–02 to 2013–12–02.pdf, Date: Tue Dec 03 09:24:06 CAT 2013 File: Cape Agulhas Store Trans for 2013–12–02 to 2013–12–02.csv, Date: Tue Dec 03 09:24:09 CAT 2013 |
- stackoverflow.com/questions/9324933/…检查这个java zip库
- 您使用的是 Java 7 吗?
- 谢谢,我会看看@pomkine
- 您可以使用 java.util.zip.ZipFile 包对其进行压缩。请找到有用的链接。
- 如果您使用的是 Java 7,请改用 FileSystem。更容易使用。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static void zip(String[] files, String zipFile) throws IOException {
BufferedInputStream origin = null; ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); try { byte data[] = new byte[BUFFER_SIZE]; for (int i = 0; i < files.length; i++) { |
来源:https://www.codenong.com/22605151/