为什么会出现 FileNotFoundException?

Why do I get FileNotFoundException?

对我来说这似乎很好,

当我尝试访问它时,我仍然得到 FileNotFoundException 吗?

请问我做错了什么?

   File cacheDir;
   if (android.os.Environment.getExternalStorageState().equals(
   android.os.Environment.MEDIA_MOUNTED))
   {
   //if SDCARD is mounted (SDCARD is present on device and mounted)
   cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
   }
   else
   {
   // if checking on simulator the create cache dir in your application context
   cacheDir=MainActivity.this.getCacheDir();
   }
   if(!cacheDir.exists()){ // create cache dir in your application context
   cacheDir.mkdirs();
   }

   String filename=String.valueOf(rss.getChannel().getItems().get(i).getEnclosure().getUrl().hashCode());

   File f = new File(cacheDir, filename);

这里

cacheDir = new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
// ...
cacheDir.mkdirs();

根据 getExternalStorageDirectory

的文档

Writing to this path requires the WRITE_EXTERNAL_STORAGE permission

此外,我建议始终检查 mkdirs 的 return 值,这表明目录创建是否成功,正如此方法的文档所述

Note that this method does not throw IOException on failure.