java.io.FileNotFoundException:(是目录)

时间:2018-10-02 06:54:47

标签: java android filenotfoundexception

if (ContextCompat.checkSelfPermission(MainActivity.getAppContext(),
                Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(MainActivity.getAppContext(), "permission denied, please enable it", Toast.LENGTH_SHORT).show();
        } else{
            Toast.makeText(MainActivity.getAppContext(), "permission granted", Toast.LENGTH_SHORT).show();
        }


        if (!mydir.exists()) {
            mydir.mkdirs();
            if (!mydir.mkdirs()) {
                Toast.makeText(MainActivity.getAppContext(), "dir not made", Toast.LENGTH_SHORT).show();
            }
        }

        File file = new File(mydir, fname);
        String s = file.getPath().toString();
        Toast.makeText(MainActivity.getAppContext(), s, Toast.LENGTH_SHORT).show();

        FileOutputStream fos = new FileOutputStream(file); //error appears here
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(this);
        oos.close();
        fos.close();

我收到以下错误,我已手动启用了该应用程序的权限:

java.io.FileNotFoundException:/storage/emulated/0/iCHMF/elasticDefault.dat(是目录)

fname是我要输出“ /elasticDefault.dat”的文件 有问题的代码行在这里。

FileOutputStream fos = new FileOutputStream(file)

0 个答案:

没有答案