FileOutputStream throws FileNotFoundException when UnZipping

前端 未结 7 1769
温柔的废话
温柔的废话 2020-12-11 04:19

I\'m using a class that I found through google to unzip a .zip file.. The .zip contains files and folder. The problem is that FileOutputStream throws

7条回答
  •  温柔的废话
    2020-12-11 04:50

    Your first version relies on dirChecker() which you haven't posted, but either it doesn't work correctly, or your ZIP file doesn't contain directory entries at all, which is prefectly legal, so you shouldn't rely on them being present anyway.

    Your second version is better but you don't need all this:

     File f = new File(Path+FileName);
              if(!f.exists())
              {
                  f.mkdirs();
                  if(!f.createNewFile())
                  {
                      f.delete();
                      f.createNewFile();
                  }
              }
    

    You just need this:

    File f = new File(Path, FileName);
    f.getParentFile().mkdirs();
    

    The rest will happen anyway.

提交回复
热议问题