集册 Java实例教程 从Zip文件中提取第一个文件

从Zip文件中提取第一个文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

418
从Zip文件中提取第一个文件

 

import java.io.FileInputStream;

import java.io.FileOutputStream;/**来 自 NowJava.com**/

import java.io.IOException;

import java.io.OutputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipInputStream;

 

public class Main {

       

        public static void main(String args[])

        {

               

                String sourceZipFile = "C:/Folder/sourceFile.zip";

               /** n o w  j a v a  . c o m 提 供 **/

                try

                {

                        FileInputStream fin = new FileInputStream(sourceZipFile);

                       

                        ZipInputStream zin = new ZipInputStream(fin);

                       

                        ZipEntry entry = zin.getNextEntry();

                       

                        OutputStream os = new FileOutputStream("c:/extractedFile.css");

                       

                        byte[] buffer = new byte[1024];

                        int length;

                       

                        while( (length = zin.read(buffer)) > 0)

                        {

                                os.write(buffer, 0, length);

                        }

                        os.close();

                       

                        zin.close();

                       

          
展开阅读全文