package com.test; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; public class ReadData { public static void main(String args[])throws Exception{ File f = new File("/home/upload/TwitterBig.zip"); InputStream in = new FileInputStream(f); byte bytes[]=new byte[(int)f.length()]; //创建合适文件大小的数组 in.read(bytes); //读取文件中的内容到b[]数组 in.close(); ByteArrayInputStream fis = new ByteArrayInputStream(bytes); ZipInputStream zis = new ZipInputStream(fis); ZipEntry ze = null; while((ze = zis.getNextEntry()) != null){ String name = ze.getName(); System.out.println("File name****"+ze.getName()); long size = ze.getSize(); byte[] binary = readZipEntry(zis,size); writeFile(binary,"/home/upload/parese/"+ze.getName()); } } private static byte[] readZipEntry(ZipInputStream zipIn, long size) throws Exception { ByteArrayOutputStream output = new ByteArrayOutputStream(); int oneByte = -1; long offset = 0L; try { while ((oneByte = zipIn.read()) > -1) { output.write((byte) oneByte); offset++; if (offset == size) { break; } } } finally { output.close(); } return output.toByteArray(); } private static void writeFile(byte[] content, String filename) throws IOException { File file = new File(filename); if (!file.exists()) { file.createNewFile(); } FileOutputStream fop = new FileOutputStream(file); BufferedOutputStream buff = new BufferedOutputStream(fop); buff.write(content); buff.flush(); buff.close(); } }