1.2.4 字符集
字符集名字大小写不敏感; 可以通过静态方法forName来获得一个Charset:
Charset cs = Charset.forName("UTF-8");
或者直接获取 java.nio.charset.StandardCharsets 里面的常量:
StandardCharsets.UTF_8 等;
1.4 Zip文档
读入Zip文件:
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname));
ZipEntry entry;
while((entry = zin.getNextEntry()) != null){
analyze entry
read the contends of zin
zin.closeEntity();
}
zin.close();
读入Zip文件内部的一个文本文件:
Scanner in = new Scanner(zin);
while(in.hasNextLine())
do something with in.nextLine();
写出Zip文件:
FileOutputStream fout= new FileOutputStream("test.zip");
ZipOutputStream zout = new ZipOutputStream(fout);
for all files
{
ZipEntry ze = new ZipEntry(filename);
zout.putNextEntry(ze);
send data to zout
zout.closeEntry();
}
zout.close();