Android open file

前端 未结 3 1959
北海茫月
北海茫月 2021-01-04 05:51

I was trying to open a file for reading.

When using: Scanner input = new Scanner(filename); the file could not be found

but when I used:

3条回答
  •  感动是毒
    2021-01-04 06:20

    This drove me crazy couple of minutes ago. I forgot to add this line to manifest:

    
    

    I would expect a permission denied message. But just got a file not found...

    In your case: openFileInput opens a file in your private app data directory (/data/data/your.package/filename). This never fails. But the scanner tries to open it on the root path. So when you want to read a file from SD card than you would use Environement.getExternalStorageDirectory().getAbsolutePath() + "/" + filename.

提交回复
热议问题