读写ZIP文件
public class TestZip {
public static void main(String[] args) throws IOException {
File file = new File("G:\\11.zip");
FileOutputStream f = new FileOutputStream(file);
CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
ZipOutputStream zos = new ZipOutputStream(csum);
BufferedOutputStream bos = new BufferedOutputStream(zos);
FileInputStream fis = new FileInputStream(
(new File(
"E:/eclipse/study/src/java/org/xlincn/study/jdk/io/TestZip.java")));
zos.putNextEntry(new ZipEntry("test.java"));
int c;
while ((c = fis.read()) != -1) {
bos.write(c);
}
fis.close();
bos.close();
FileInputStream fi = new FileInputStream(file);
CheckedInputStream cium = new CheckedInputStream(fi, new Adler32());
ZipInputStream zin = new ZipInputStream(cium);
BufferedReader br = new BufferedReader(new InputStreamReader(zin));
ZipEntry ze;
while ((ze = zin.getNextEntry()) != null) {
String s;
while ((s = br.readLine()) != null) {
System.out.println(s);
}
}
}
}
递归
static void getFile(String name) throws IOException {
File file = new File(name);
File[] f = file.listFiles();
for (int i = 0; i < f.length; i++) {
if (f[i].isDirectory()) {
getFile(f[i].getAbsolutePath());
}
System.out.println("name=" + f[i].getAbsolutePath());
}
}