读取zip文件,然后根据读取的数据在创建个zip

功能接收zip文件流,然后创建zip文件,现在想自己先写个demo读取zip文件,然后根据读取的数据在创建个zip

2个回答

 HttpPost httppost = new HttpPost(url);  

            FileBody bin = new FileBody(new File(zipPath));  //zipPath压缩包路径
            StringBody comment = new StringBody(zipName);  
            Charset charSet=Charset.forName("UTF-8");
            StringBody context = new StringBody(obj.toString(),charSet); 
            HttpEntity reqEntity =MultipartEntityBuilder.create().addPart("file", bin).addPart("filename", comment).build();
            httppost.setEntity(reqEntity);
            HttpResponse response = httpclient.execute(httppost);  
            int statusCode = response.getStatusLine().getStatusCode(); 

package com.unplatform.vis.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipFileListUtil {

static final int BUFFER = 8192;

private File zipFile;   

public ZipFileListUtil(String pathName) {   
    zipFile = new File(pathName);   
}   
public void compress(File[] fileName) { 
    ZipOutputStream out = null;   
    try {  
        FileOutputStream fileOutputStream = new FileOutputStream(zipFile);   
        CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream,   
                new CRC32());   
        out = new ZipOutputStream(cos);   
        String basedir = ""; 
        for (int i=0;i<fileName.length;i++){
            compress(new File(fileName[i].getAbsolutePath()), out, basedir);   
        }
        out.close();  
    } catch (Exception e) {   
        throw new RuntimeException(e);   
    } 
}   
public void compress(String srcPathName) {   
    File file = new File(srcPathName);   
    if (!file.exists())   
        throw new RuntimeException(srcPathName + "不存在!");   
    try {   
        FileOutputStream fileOutputStream = new FileOutputStream(zipFile);   
        CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream,   
                new CRC32());   
        ZipOutputStream out = new ZipOutputStream(cos);   
        String basedir = "";   
        compress(file, out, basedir);   
        out.close();   
    } catch (Exception e) {   
        throw new RuntimeException(e);   
    }   
}   

private void compress(File file, ZipOutputStream out, String basedir) {   
    /* 判断是目录还是文件 */  
    if (file.isDirectory()) {   
        System.out.println("压缩:" + basedir + file.getName());   
        this.compressDirectory(file, out, basedir);   
    } else {   
        System.out.println("压缩:" + basedir + file.getName());   
        this.compressFile(file, out, basedir);   
    }   
}   

/** 压缩一个目录 */  
private void compressDirectory(File dir, ZipOutputStream out, String basedir) {   
    if (!dir.exists())   
        return;   

    File[] files = dir.listFiles();   
    for (int i = 0; i < files.length; i++) {   
        /* 递归 */  
        compress(files[i], out, basedir + dir.getName() + "/");   
    }   
}   

/** 压缩一个文件 */  
private void compressFile(File file, ZipOutputStream out, String basedir) {   
    if (!file.exists()) {   
        return;   
    }   
    try {   
        BufferedInputStream bis = new BufferedInputStream(   
                new FileInputStream(file));   
        ZipEntry entry = new ZipEntry(basedir + file.getName());   
        out.putNextEntry(entry);   
        int count;   
        byte data[] = new byte[BUFFER];   
        while ((count = bis.read(data, 0, BUFFER)) != -1) {   
            out.write(data, 0, count);   
        }   
        bis.close();   
    } catch (Exception e) {   
        throw new RuntimeException(e);   
    }   
}   

}

package com.unplatform.vis.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZipUtil {
private static final Logger logger = LoggerFactory.getLogger(ZipUtil.class);
/**
* 压缩成ZIP文件
* zipFileName 压缩后文件路径 inputFile待压缩文件夹目录
**/
public static void zip(String zipFileName, File inputFile) throws Exception {
logger.info("压缩文件夹中...");
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
BufferedOutputStream bo = new BufferedOutputStream(out);
//zip(out, inputFile, inputFile.getName(), out);
zip(out, inputFile, inputFile.getName(), bo);
bo.close();
out.close(); // 输出流关闭
logger.info("压缩文件夹完成");
}

public static void zip(ZipOutputStream out, File f, String base,BufferedOutputStream  bo) throws Exception { // 方法重载
    if (f.isDirectory()) {
        File[] fl = f.listFiles();
        if (fl.length == 0) {
            out.putNextEntry(new ZipEntry(base + "/")); // 创建zip压缩进入点base
            //System.out.println(base + "/");
        }
        for (int i = 0; i < fl.length; i++) {
            zip(out, fl[i], base + "/" + fl[i].getName(), bo);// 递归遍历子文件夹
        }
        bo.flush();
    } else {
        out.putNextEntry(new ZipEntry(base)); // 创建zip压缩进入点base
        //System.out.println("-------------base:"+base);
        FileInputStream in = new FileInputStream(f);
        BufferedInputStream bi = new BufferedInputStream(in);
        int b;
        while ((b = bi.read()) != -1) {
            bo.write(b); // 将字节流写入当前zip目录
        }

        bo.flush();

// byte[] buf = new byte[1024*1024];
// while ((b = in.read(buf)) != -1) {
// bo.write(buf, 0, b);
// }

        bi.close();
        in.close(); // 输入流关闭
    }
}




/*解压缩
 * zipFileName 源zip路径 ,unZipPath 输出路径(文件夹目录)
 * */
public static void unZip(String zipFileName,String unZipPath){
    logger.info("开始解压ZIP文件: "+zipFileName);
    long startTime=System.currentTimeMillis();
    try {
        ZipInputStream zin=new ZipInputStream(new FileInputStream(zipFileName));//输入源zip路径
        BufferedInputStream bin=new BufferedInputStream(zin);
        File Fout=null;
        ZipEntry entry;
        try {
            while((entry = zin.getNextEntry())!=null ){
                if(entry.isDirectory()){
                    //目录
                    Fout=new File(unZipPath,entry.getName());
                    if(!Fout.exists()){
                        Fout.mkdirs();
                    }
                }else{
                    //文件
                    Fout=new File(unZipPath,entry.getName());
                    if(!Fout.exists()){
                        (new File(Fout.getParent())).mkdirs();
                    }
                    FileOutputStream out=new FileOutputStream(Fout);
                    BufferedOutputStream Bout=new BufferedOutputStream(out);
                    int b;
                    while((b=bin.read())!=-1){
                        Bout.write(b);
                    }
                    Bout.flush();
                    Bout.close();
                    out.close();
                }
                //System.out.println(Fout+"解压成功");  
            }
            bin.close();
            zin.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    long endTime=System.currentTimeMillis();
    logger.info("解压ZIP文件耗时: "+(endTime-startTime)+" ms");
}

// public static void main(String[] args) {
// ZipUtil book = new ZipUtil();

// try {
// //book.zip("d:\zl.zip",new File("d:\zl"));
// //book.unZip("d:\Huatai2_1.5.zip","e:\");
// book.zip("Z:\ceshi.zip",new File("Z:\测试输出"));
//
// } catch (Exception e) {

// e.printStackTrace();

// }

// }

/** 
 * 加载本地文件,并转换为byte数组 
 * @return 
 */  
public static byte[] loadFile(String zipFileName) {  
    File file = new File(zipFileName);  
    FileInputStream fis = null;  
    ByteArrayOutputStream baos = null;  
    byte[] data = null ;  

    try {  
        fis = new FileInputStream(file);  
        baos = new ByteArrayOutputStream((int) file.length());  

        byte[] buffer = new byte[1024];  
        int len = -1;  
        while ((len = fis.read(buffer)) != -1) {  
            baos.write(buffer, 0, len);  
        }  

        data = baos.toByteArray() ;  

    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        try {  
            if (fis != null) {  
                fis.close();  
                fis = null;  
            }  

            baos.close() ;  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  

    return data ;  
} 

/** 
 * 对byte[]进行压缩 
 *  
 * @param 要压缩的数据 
 * @return 压缩后的数据 
 */  
public static byte[] compress(byte[] data) {  
    System.out.println("before:" + data.length);  

    GZIPOutputStream gzip = null ;  
    ByteArrayOutputStream baos = null ;  
    byte[] newData = null ;  

    try {  
        baos = new ByteArrayOutputStream() ;  
        gzip = new GZIPOutputStream(baos);  

        gzip.write(data);  
        gzip.finish();  
        gzip.flush();  

        newData = baos.toByteArray() ;  
    } catch (IOException e) {  
        e.printStackTrace();  
    } finally {  
        try {  
            gzip.close();  
            baos.close() ;  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  

    System.out.println("after:" + newData.length);  
    return newData ;  
}  

}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
ios读取zip文件
IOS能不能不解压带密码的zip文件而直接读取里面某个文件的内容?
读取ZIP文件
[code=&quot;java&quot;] import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map;[code=&quot;java&quot;][/code] import java.util.Timer; import java.util.TimerTask; i...
java读取zip文件
import java.io.IOException; import java.util.Enumeration; import java.util.zip.ZipEntry; /** * 获得zip文件里的所有文件 * @author Administrator * */ public class ZipFile { public ZipFile() ...
zip文件解压读取
Constants.FILE_PATH_FULL).append(Constants.ZIP_FILE_NAME:zip文件全路径
读取zip文件
package com.me.admin.test; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import jav...
python读取zip文件
def read_data(filename): """Extract the first file enclosed in a zip file as a list of words""" with zipfile.ZipFile(filename) as f: data = tf.compat.as_str(f.read(f.namelist()[0])).s...
Zip文件的读取处理
String batchImportPPAPFile() {         String successStr;         request.fileNames.each {             //读取sheet页             MultipartFile multipartFile = request.getFile(it);                       ...
如何创建、读取一个zip文件
求创建、读取一个zip文件的代码rn
创建与读取ZIP/RAR压缩文件
使用AS3创建与读取ZIP文件,最早也是最流行的是Fzip开源包了,但Fzip没有提供生成ByteArray二进制数据的方法,在AIR中创建压缩包并成了问题,不过这个开源类用在基于WEB的服务器上通过插件方式还是不错。一些Fzip资料官方站:http://codeazur.com.br/lab/ 后来,发现有个国内的开源包,ZipArchive基于AIR的包可以使用output()方法输出成...
python读取las数据.zip
采用python开发平台,对点云Las数据进行读取并三维可视化显示,调用第三方库对每个点建立kd树,实验验证效率较高。
python读取txt数据.zip
采用python语言,实现txt文本格式点云数据读取,并进行三维可视化
12_文件的保存与读取.zip
12_文件的保存与读取.zip
纯内存读取Zip文件
总结方法1完全内存读取,只需要一个输入流即可; 方法2必须从操作系统本地读取文件才行,不能做到完全的内存读取;方法1public static void readZipFile0(InputStream in) throws Exception { ZipInputStream zis = new ZipInputStream(in); ZipEntry entry = null;
C#读取.nc文件.zip
因为需要解析风云4卫星NC文件,在网上找了很多资料版本,还是没有找到直接可用的代码,于是自己研究捣鼓了下,出了一个这个版本。欢迎大家下载共同探讨。解析采用动态库为netCDF 4.7.0 c语言的32位版本代码,因此如果为.net 4.5以上编译项目目标平台首选32位需要勾上,如果以下版本,需要把目标平台设置为x86
读取zip文件中xml文件
  package com.oppo; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.zip.ZipEntry...
根据类型,读取zip文件中单个文件的内容
读取zip文件中的文件内容
解压zip文件,读取zip文件中的详细信息程序代码
NULL 博文链接:https://richling.iteye.com/blog/740822
ios-读取手机通讯录.zip
一款能够读取手机联系人的Demo,解决项目中需要手机中联系人电话号码的需求. 开发者的你,值得拥有!
读取ZIP中的txt文件
背景: 根据客户需求,导入功能需要读取ZIP文件中的多个ZIP文件,再分别读取每个ZIP文件中的txt内容,从而将其导入数据库中。这里涉及到的知识点是1、读取ZIP 2、读取文件流 3、循环插入数据库。详细内容: 将该功能做成一个工具类,参数定义为文件路径。之所以需求要求读取一个ZIP下的多个ZIP,是因为涉及到多文件上传服务器,使用浏览器为IE8,无法兼容HTML5,分析后采用将多个zip整合成
python读取zip压缩文件
import pandas as pd pd.set_option('display.max_columns', 500) import zipfile with zipfile.ZipFile('KaggleCredit2.csv.zip', 'r') as z: f = z.open('KaggleCredit2.csv') data = pd.read_csv(f, inde
java-读取zip文件内容
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream;public class zipInput { public st
java读取ZIP问题
rnimport java.util.*;rnimport java.io.*;rnimport java.util.zip.*;rnrnpublic class Arnrn public void readWriteZip() throws Throwablern rn ZipInputStream zin=new ZipInputStream(new BufferedInputStream(new FileInputStream("test.zip")));rn ZipOutputStream zout=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream("receive.zip")));rn ZipEntry entry;rn int data;rn String entryName;rnrn while((entry=zin.getNextEntry())!=null)rn rn entryName=entry.getName();rn ZipEntry ze=new ZipEntry(entryName);rn zout.putNextEntry(ze);rnrn while((data=zin.read())!=-1)rn rn zout.write(data);rn rn zout.closeEntry();rn zin.closeEntry();rn rn zout.close();rn zin.close();rn rn public static void main(String[] args) throws Throwablern rn long start=System.nanoTime();rn A a=new A();rn a.readWriteZip();rn System.out.println(System.nanoTime()-start);rn rnrnrn为什么当ZIP文件中有文件夹时,报错IllegalArgumentException?比如ZIP中有个文件夹,文件夹里有二个文本.如果要在ZIP中包含文件夹时也能正确读写,应该怎么做?(该代码的功能只是将当前目录的test.zip文件复制到receive.zip中)
cocos2d-x 读取zip的代码
简单的 读取zip包的代码,可以获取到里面的信息
java 读取zip Demo
java 读取zip Demo java 读取zip Demo
C#读取CAD表格数据.zip
Winform调用AutoCAD的dwg文件,实现对dwg文件中的表格数据进行读取操作。
JSZip使用Javascript创建读取和编辑zip文件
JSZip 使用Javascript创建,读取和编辑.zip文件
java 直接读取zip文件和文件内容
不解压zip文件,直接读取zip包内的文件夹以及文件内容
读取zip文件(中文文件名)报错问题
异常: java.lang.IllegalArgumentException: MALFORMED 原代码: public static void readZipFile(String file) throws Exception { File fileNew = new File(file); java.util.zip.ZipFile zf = new java.util.zip...
求助,ZIP文件直接读取内容
我有500个ZIP文件,每个文件里面都有几百个文本文件,有没有什么办法可以不解压缩,而直接读取zip文件中的文本文件的内容?因为全部解压要4G左右的空间,太占空间了。
ZipInputStream类读取普通zip文件的问题
使用winrar自己压缩的文件,其中有文件是中文名称。 rn 使用ZipInputStream类读取此zip文件时候,当想取出其中那个中文名称的文件名ZipEntry.getName()时,抛出异常IllegalArgumentException,怎么办啊?
php读取csv文件类.zip
介绍一个php读取csv文件类。 csv是逗号分隔值文件格式,一般用WORDPAD或记事本(NOTE),EXCEL打开。 csv(逗号分隔值)是一种用来存储数据的纯文本文件,通常都是用于存放电子表格或数据的一种文件格式。
java直接读取Zip压缩包内的文件
//zip数据处理 public List&lt;Map&lt;String,Object&gt;&gt; readZipFile(String file,ChironUser user) throws Exception { //ZipFile zf = new ZipFile(file); int i=0; List&lt;Map&lt;String,Object&g...
解压zip文件,并按行读取读取,返回list
public static Map&amp;lt;String,Object&amp;gt; zipReadMethodTest2(BufferedInputStream file) throws Exception{ ZipInputStream zipIn = new ZipInputStream(file,Charset.forName(&quot;GBK&quot;)); InputStreamReader read =...
读取写入tar/zip文件(go语言)
1.读取写入tar文件 package main import ( "archive/tar" "fmt" "os" "bufio" "io" ) func readFile(path string) string{ var content string = "" file,err := os.Open(path) if err
C# 读取zip文件慢的问题
public string encode(string path) //这个是编码zip文件的rn rn string message = string.Empty;rnrn tryrn rn FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);rn byte[] bytes = new byte[fs.Length];rn fs.Read(bytes, 0, bytes.Length);rn fs.Flush();rn fs.Close();rnrn StringBuilder sb = new StringBuilder();rn for (int i = 0; i < bytes.Length - 1; i++)rn rn sb.AppendFormat("0:x2", bytes[i]);rn rn message = sb.ToString();rn return message;rn rn catch (Exception e)rn rn message = "文件压缩错误";rn return message;rn rn rnrnprivate void button1_Click(object sender, EventArgs e)rn rn OpenFileDialog op = new OpenFileDialog();rn op.InitialDirectory = "D:\\";rn op.Filter = "Zip文件|*.zip";rn op.FilterIndex = 1;rn if (op.ShowDialog() == DialogResult.OK)rn rn string fn = op.FileName;rn string content= new encode(fn);rn this.textBox1.AppendText(content); //内容在textbox1上显示 rn rn rnrn//------问什么打开一个32KB的zip文件 显示到textBox1 上要7、8秒的时间啊 有没有读文件快速一点的方法啊?
无法读取zip文件.大家帮帮忙!!
在程序运行时有如下信息:rnException in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionrn at ZipTestFrame.scanZipFile(ZipTest.java:78)rn at ZipTestFrame$OpenAction.actionPerformed(ZipTest.java:70)rn at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2013)rn at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2336)rn at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)rn at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260)rn at javax.swing.AbstractButton.doClick(AbstractButton.java:375)rn at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1689)rn at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1733)rn at java.awt.Component.processMouseEvent(Component.java:6100)rn at javax.swing.JComponent.processMouseEvent(JComponent.java:3288)rn at java.awt.Component.processEvent(Component.java:5865)rn at java.awt.Container.processEvent(Container.java:2110)rn at java.awt.Component.dispatchEventImpl(Component.java:4461)rn at java.awt.Container.dispatchEventImpl(Container.java:2168)rn at java.awt.Component.dispatchEvent(Component.java:4287)rn at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4466)rn at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4130)rn at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4060)rn at java.awt.Container.dispatchEventImpl(Container.java:2154)rn at java.awt.Window.dispatchEventImpl(Window.java:2555)rn at java.awt.Component.dispatchEvent(Component.java:4287)rn at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)rn at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:276)rn at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)rn at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)rn程序如下:rnrnimport java.awt.BorderLayout;rnimport java.awt.event.ActionEvent;rnimport java.awt.event.ActionListener;rnimport java.io.*;rnimport java.util.ArrayList;rnimport java.util.zip.ZipEntry;rnimport java.util.zip.ZipInputStream;rnimport javax.swing.*;rnimport javax.swing.filechooser.FileFilter;rnpublic class lianxi rnpublic static void main(String[] args)rnrn ZipTestFrame f=new ZipTestFrame();rn f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn f.setVisible(true);rnrnrnclass ZipTestFrame extends JFramernrn public ZipTestFrame()rn rn setTitle("ZipTest");rn setSize(100,100);rn rn JMenuBar menuBar=new JMenuBar();rn rn JMenu menu=new JMenu("文件");rn JMenuItem menu1=new JMenuItem("打开");rn menu1.addActionListener(new OpenAction());rn JMenuItem menu2=new JMenuItem("退出");rn menu2.addActionListener(new ActionListener()rn rn public void actionPerformed(ActionEvent event)rn System.exit(0);rn rn );rn menu.add(menu1);rn menu.add(menu2);rn menuBar.add(menu);rn setJMenuBar(menuBar);rn JTextArea filetext=new JTextArea();rn final JComboBox fileCombo=new JComboBox();rn fileCombo.addActionListener(new ActionListener()rn public void actionPerformed(ActionEvent event)rn loadZipFile((String)fileCombo.getSelectedItem());rn rn );rn add(fileCombo,BorderLayout.SOUTH);rn add(new JScrollPane(filetext),BorderLayout.CENTER);rn rn private class OpenAction implements ActionListenerrn rn public void actionPerformed(ActionEvent event)rn JFileChooser chooser=new JFileChooser();rn chooser.setCurrentDirectory(new File("."));rn ExtensionFileFilter filter=new ExtensionFileFilter();rn filter.addExtension(".zip");rn filter.addExtension(".jar");rn filter.setDescription("ZIP archives");rn chooser.setFileFilter(filter);rn int r=chooser.showOpenDialog(ZipTestFrame.this);rn if(r==JFileChooser.APPROVE_OPTION)rn zipname = chooser.getSelectedFile().getPath();rn scanZipFile();rn rn rn rn rn public void scanZipFile()rn rn rn fileCombo.removeAllItems();rn tryrn rn ZipInputStream zin=new ZipInputStream(new FileInputStream(zipname));rn ZipEntry entry;rn while((entry=zin.getNextEntry())!=null);rn rn fileCombo.addItem(entry.getName());rn zin.closeEntry();rn rn zin.close();rn rn catch(IOException e)rn rn e.printStackTrace();rn rn rn public void loadZipFile(String name)rn rn tryrn rn rn ZipInputStream zin=new ZipInputStream(new FileInputStream(zipname));rn ZipEntry entry;rn filetext.setText("");rn while((entry=zin.getNextEntry())!=null)rn rn if(entry.getName().equals(name))rn rn BufferedReader in=new BufferedReader(new InputStreamReader(zin));rn String line;rn while((line=in.readLine())!=null)rn rn filetext.append(line);rn filetext.append("\n");rn rn rn zin.closeEntry();rn rn zin.close();rn rn catch (IOException e)rn rn e.printStackTrace();rn rn rn private JComboBox fileCombo;rn private JTextArea filetext;rn private String zipname;rnrnrnrnclass ExtensionFileFilter extends FileFilterrnrn public void addExtension(String extension)rn rn if(!extension.startsWith("."));rn extension="."+extension;rn extensions.add(extension.toLowerCase());rn rn public void setDescription(String aDescription)rn rn description=aDescription;rn rn rn public String getDescription()rn rn return description;rn rn public boolean accept(File f)rn rn if(f.isDirectory()) return true;rn String name=f.getName().toLowerCase();rn for(String e:extensions)rn if (name.endsWith(e))rn return true;rn return false;rn rn private String description="";rn private ArrayList extensions=new ArrayList();rnrn希望高手们帮帮忙!!我弄了很久了 不得其解!!rnrn
如何读取zip包中的文件
是这样的,我现在想在程序中读取zip包中的文件,不能解压到磁盘上,而是直接读取,zip包中可能有文件夹,文件夹里有文件,通过给定的文件全路劲名称读取zip包中的文件。希望大神给点思路。。谢谢啦~
在Symbian OS中读取ZIP文件
在Symbian OS中读取ZIP文件, 在Symbian OS中读取ZIP文件。
读取zip压缩文件中每个文件的名字
public Test() throws IOException { java.util.zip.ZipFile zf = new java.util.zip.ZipFile(&quot;d:/Archive.zip&quot;); Enumeration e = zf.entries(); while(e.hasMoreElements()) { ...
java读取zip中指定文件
[code=&quot;java&quot;] public static void main(String args[]) { String file = &quot;c://ssi.zip&quot;; String saveRootDirectory = &quot;c://test/&quot;; new TestZip().zipFileRead(file, saveRootDirectory); } /** ...
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法