【发布时间】:2013-09-13 10:47:41
【问题描述】:
当我制作 File file = new File(etc..) 时,我实际上在 SD 卡上创建了该文件?我有点困惑,因为每次我的条件为真并且程序跳转到 if 树但那时 SD 卡上没有文件...
String filename = "pictures.data";
String root = Environment.getExternalStorageDirectory().toString();
File dir = new File(root + "/courier/saved/");
File file = new File(dir,filename);
if (file.exists())
// program jumps here
else{
}
【问题讨论】:
-
为什么使用
toString()方法?您可以使用返回字符串的File.getPath()。 -
PRint 变量根。 getExternalStorageDirectory() 不能可靠地提供 sd 卡位置(我已经看到不同的设备为此表现不同)。一旦你确认根变量确实指向外部 SD 卡,那么你可以进一步挖掘
-
/storage/sdcard0 是我的外部存储,所以 /storage/sdcard0/courier/saved/ 被添加到路径中
标签: android file file-exists