ZipInputStream zipIsStream = new ZipInputStream(new FileInputStream(filename));我想问一下,在正在解压的过程中,如果解压文件不存在了,这个时候会出现什么问题???我目前遇到的就是:正在解压文件,但是这个文件已经不存在了(就是强制卸载掉文件,这个文件在u盘上,把U盘拔掉),只能解压出文件中部分文件。

解决方案 »

  1.   

    给你贴个方法我自己的代码 /*此方法用于测试*/
    public boolean zip(File infile, File osfile) throws IOException {
    FileInputStream in = null;
    ZipOutputStream os = null;
    try {
    os = new ZipOutputStream(new FileOutputStream(osfile));
    File[] fs = infile.listFiles();
    for (int i = 0, count = fs.length; i < count; i++) {
    in = new FileInputStream(fs[i]);
    os.putNextEntry(new org.apache.tools.zip.ZipEntry(fs[i].getName()));
    byte[] b = new byte[2048];
    int len;
    while ((len = in.read(b)) > 0) {
    os.write(b, 0, len);
    }
    os.flush();
    os.closeEntry();
    in.close();
    }
               
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (in != null) {
    in.close();
    }
    if (os != null) {
    os.close();
    }
    } return true;
    } public static void main(String[] args) {
    Queryfileinfo m_zip = new Queryfileinfo();
    try {
    m_zip.zip(new File("D:\\tomcatoracle\\webapps\\yqoa\\download"), new File("D:\\a.zip"));


    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }
    需要一个包,ant.jar
      

  2.   

    while ((z = in.getNextEntry()) != null) 
    {
        if (z.getName().equals(getNoChooseModules(mNeededChangeList, z.getName())))
        {
    continue;
        }
        if (!z.isDirectory())
       {
    File f = new File(ThemeConstants.mUnzipPath+ z.getName());
    File themefilepath = new File(ThemeConstants.mUnzipPath);
    if (themefilepath.exists()) 
    {
    Log.d(TAG, "themefilepath is exists");

    else 
    {
    String command1 = "/system/bin/mkdir   /data/THEME";
    Runtime runtime1 = Runtime.getRuntime();
    try 
    {
    runtime1.exec(command1);

    catch (Exception e) 
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    }
    try 
    {
    boolean tempBe = f.createNewFile();
    if(tempBe == false)


    catch (Exception e) 
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    ThemeManagerApplication.getInstance().exit();
    return; }
    FileOutputStream out = new FileOutputStream(f);
    int b;
    byte[] buffer = new byte[4096];
    while ((b = in.read(buffer)) > 0)
        out.write(buffer, 0, b);
    out.close();
                                          //貌似,我没像你的那样刷新缓冲,判断空指针的问题应该不存在,如果是空指针,log信息会报错,现在就是,当我解压文件的,解压的一半的时候,我把文件搞掉,就是文件是手机SD卡中的,
    解压到一半,我把手机USB模式调成 :打开存储功能,这个时候,手机上的软件正在解压手机SD卡中的文件,手机的USB却是连接到了电脑上,软件就找不到正在解压到文件了,这样会不会导致手机死掉?
    in.close();