1. 程式人生 > >android FileNotFoundException錯誤:建立檔案失敗 No such file or directory

android FileNotFoundException錯誤:建立檔案失敗 No such file or directory

在Android真機上測試時報錯:java.io.FileNotFoundException: /storage/emulated/0/DownFile/。。。: open failed: ENOENT (No such file or directory)

報錯:

java.io.FileNotFoundException: /storage/emulated/0/DownFile/。。。: open failed: ENOENT (No such file or directory)

路徑:

 String savePAth = Environment.getExternalStorageDirectory() + "/DownFile/"
;

建立時一直失敗。
需要把路徑改為:

String savePAth = getExternalCacheDir()+"/DownFile/";