以下代码包括从服务器下载文件并将其保存在存储中,当设备具有内部存储时可以正常工作.
但是当我使用没有内部存储的设备尝试它时,只有外部存储器,我得到以下异常.
java.io.filenotfoundexception打开失败的eacces(权限被拒绝)
public void downloadFile(String dlUrl, String dlName) {
int count;
HttpURLConnection con = null;
InputStream is = null;
FileOutputStream fos = null;
try {
URL url = new URL( dlUrl );
con = (HttpURLConnection) url.openConnection();
con.setDoInput(true);
con.connect();
is = url.openStream();
String dir = Environment.getExternalStorageDirectory() + Util.DL_DIRECTORY;
File file = new File( dir );
if( !file.exists() ){
file.mkdir();
}
Util.LOG_W(TAG, "Downloading: " + dlName + " ...");
fos = new FileOutputStream(file + "/" + dlName);
byte data[] = new …Run Code Online (Sandbox Code Playgroud)