创建邮政编码档案
import java.io.*; /* 时 代 Java 公 众 号 - nowjava.com */ import java.util.HashMap; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class CreateZipArchive { public static void main(String[] args) { HashMap<String,File> files = new HashMap<String, File>() {{ put("count-chars.txt",new File("files/count-chars.txt")); put("words.txt",new File("files/words.txt")); put("lines.txt",new File("files/lines.txt")); /** 时 代 J a v a 公 众 号 - nowjava.com **/ }}; zipFiles(files,"files/text-files.zip"); } public static void zipFiles(Map<String,File> files,String archiveName) { try(ZipOutputStream destination = new ZipOutputStream(new FileOutputStream(archiveName))){ for(Map.Entry<String,File> file : files.entrySet()){ try(FileInputStream source = new FileInputStream(file.getValue())){ destination.putNextEntry(new ZipEntry(file.getKey())); byte[] buffer = new byte[4096]; while(true){ int readed = source.read(buffer,0,buffer.length);