Java 我的代码将目录检测为文件,将文件检测为目录

Java 我的代码将目录检测为文件,将文件检测为目录,java,android,Java,Android,我的代码将目录检测为文件,将文件检测为目录。它为什么这样做?谢谢 我已经攻击了发生问题的完整函数,如果它很混乱,请道歉!再次感谢你的帮助 unzip(getFilesDir() + "/", "bla.zip", getFilesDir() + "/unzip/"); public void unzip(String filepath, String filename, String unzip_path) { try { InputStream is = new F

我的代码将目录检测为文件,将文件检测为目录。它为什么这样做?谢谢

我已经攻击了发生问题的完整函数,如果它很混乱,请道歉!再次感谢你的帮助

unzip(getFilesDir() + "/", "bla.zip", getFilesDir() + "/unzip/");

 public void unzip(String filepath, String filename, String unzip_path) {
    try {
        InputStream is = new FileInputStream(filepath + filename);

    Log.d("1st", filepath + filename);
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));

    try {
        ZipEntry ze;
        while ((ze = zis.getNextEntry()) != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int count;

            String filename_temp = ze.getName();
            File fmd = new File(unzip_path, filename_temp);
            Log.d("2nd", unzip_path + filename_temp);
            Log.d("ERROR7", fmd.toString());
            //if (!fmd.exists()) {
                if(fmd.isDirectory()) {
                    Log.d("ERROR4", fmd.toString());
                    fmd.mkdirs();
                } else if (fmd.isFile()) {
                    Log.d("ERROR4", fmd.toString() +"FILE");
                }

            //} else {}
            Log.d("ERROR5", "DIR");
            FileOutputStream fout = new FileOutputStream(unzip_path + filename_temp);
            Log.d("ERROR6", "DIR");
            while ((count = zis.read(buffer)) != -1) {
                baos.write(buffer, 0, count);
                byte[] bytes = baos.toByteArray();
                fout.write(bytes);
                baos.reset();
            }

            fout.close();
            //}
        }
        zis.close();
    } catch (IOException e) {
        Log.d("ERROR1", e.toString());
    }} catch (FileNotFoundException e) {            Log.d("ERROR2", e.toString());}
}

1st﹕ /data/data/au.com.amon/files/bla.zip
2nd﹕ /data/data/au.com.amon/files/unzip/docProps/
 ERROR7﹕ /data/data/au.com.amon/files/unzip/docProps
ERROR4﹕ /data/data/au.com.amon/files/unzip/docPropsFILE
ERROR5﹕ DIR
ERROR6﹕ DIR
2nd﹕ /data/data/au.com.amon/files/unzip/docProps/app.xml
ERROR7﹕ /data/data/au.com.amon/files/unzip/docProps/app.xml
ERROR5﹕ DIR
ERROR1﹕ java.io.FileNotFoundException: /data/data/au.com.amon/files/unzip/docProps/app.xml: open failed: ENOTDIR (Not a directory)
DOCUMENT﹕ docProps
请尝试以下操作:

File fmd = new File(getFilesDir() + "/unzip/", filename_temp);

您使用的是表示路径名而不是文件名的单字符串arg构造函数。

您的代码没有意义。从ZIP文件读取的文件名不一定代表磁盘上已经存在的文件,也不代表由其构造的
文件。因此,对它进行
isDirectory()
测试是徒劳的,而测试它以确定是否应该调用
mkdirs()
则更是徒劳。如果是目录,则不应调用
mkdirs()


您应该检查的是
ZipEntry.isDirectory()。

可以
File fmd=new File(getFilesDir()+“/unzip/”,filename\u temp)可能有效?该文件是否确实存在于磁盘上?如果不是,则
isFile()
isDirectory()
都将返回
false
。它将从zip文件中提取。这就是我要澄清的错误,他添加了一个逗号
新文件(路径+“/”+名称)
新文件(路径,名称)
(a)不能解释这个问题,并且(b)为零。哦……我该怎么办?感谢您的帮助