当我尝试从服务器下载zip文件时遇到问题。我使用intentservice下载文件但我得到了这个例外
java.io.FileNotFoundException: /storage/emulated/FileTest1.zip: open failed: EACCES (Permission denied)
我尝试将文件保存在内部存储上,而不是保存在SD卡上。 这是我的代码
@Override
protected void onHandleIntent(Intent intent) {
String urlDir = intent.getExtras().getString(DOWNLOAD_SERVICE_URL);
String fileName = intent.getExtras().getString(DOWNLOAD_SERVICE_FILE_NAME);
String filePath = intent.getExtras().getString(DOWNLOAD_SERVICE_FILE_PATH);
try{
URL url = new URL(urlDir);
URLConnection connection = url.openConnection();
connection.connect();
BufferedInputStream input = new BufferedInputStream(url.openStream());
String tempName = filePath + fileName;
FileOutputStream output = new FileOutputStream(tempName);
byte data[] = new byte[1024];
while (input.read(data) != -1) {
output.write(data);
}
output.flush();
output.close();
input.close();
} catch(Exception e){
e.printStackTrace();
}
}
我该如何解决?