爲什麼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」);嘗試你的道路就像餵我回 –