在Android中读取文件时文件不存在

时间:2013-07-29 05:19:53

标签: android

  File file = new File("file:///storage/sdcard0/myfile.txt");
  if (file.exists()) {
     //...
  }

我看到该文件在我的SD卡中,但为什么file.exists()总是返回false?

2 个答案:

答案 0 :(得分:1)

尝试不使用file://

File file = new File("/storage/sdcard0/myfile.txt");
  if (file.exists()) {
     //...
  }

答案 1 :(得分:0)

试试这个 -

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfile.txt");
if (file.exists()) {
 //...
}
相关问题