为什么f不是文件?什么可能造成这种情况?Android新建文件(路径)
String currentPhotoPath = "file:/storage/sdcard0/Pictures/someFileName.jpg";
...
File f = new File(currentPhotoPath);
if (f == null || !f.isFile()) {
// This gets executed
}
为什么f不是文件?什么可能造成这种情况?Android新建文件(路径)
String currentPhotoPath = "file:/storage/sdcard0/Pictures/someFileName.jpg";
...
File f = new File(currentPhotoPath);
if (f == null || !f.isFile()) {
// This gets executed
}
你尝试过吗?
String filePath = Environment.getExternalStorageDirectory().toString() + "/Pictures";
String fileName = "someFileName.jpg";
File f = new File(filePath,filename);
我真的很震惊,它的工作。谢谢。 – chuckfinley
在Java中,File
实例也可以是目录或不存在的文件。有关其执行的检查的详细信息,请参阅the reference of isFile
。
在你的情况,但是,我认为主要的问题是,你与一个URI初始化File
实例,但使用构造实际路径。您可以使用带有文件名的构造函数,也可以使用constructor using URI
objects。
他们怎么这样做这种方式呢? http://developer.android.com/training/camera/photobasics.html – chuckfinley
你确认它有效吗?路径的实际风格未在文档中定义,因为它可能与平台有关。也许Android允许路径以'file:'开始?至少在[OpenJDK](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/File.java)中,实现是针对'使用FileSystem'。所以,如果作品Android的文件系统支持,我猜。 – dst
@chuckfinley我只是在链接的页面上查看下载内容,然后在那里使用实际路径。 – dst
File f = new File(“/ mnt/sdcard/photo.jpg”);尝试你的道路就像喂我回 –