始终在Android中拒绝FileNotFoundException权限 [英] Always FileNotFoundException Permission Denied in android
问题描述
为什么我总是收到此错误FileNotFoundException权限被拒绝?代码运行顺利,但是当我单击文件下载时,将不会下载该文件.请帮我.我是新来的
Why do i always get this error FileNotFoundException Permission Denied? The code is going smooth but when i click a file to download, it wont be downloaded. Please help me. im new to this
这是我的logcat
Here is my logcat
03-28 09:19:34.695: E/log_tag(17921): eer java.io.FileNotFoundException: /mnt/sdcard/Excel.xlsx (Permission denied)
在我的清单上
<uses-sdk android:minSdkVersion="11"
android:targetSdkVersion="15"
android:maxSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
这是我的下载功能
//Download
public void startDownload(final int position) {
Runnable runnable = new Runnable() {
int Status = 0;
public void run() {
String urlDownload = MyArrList.get(position).get("FileUrl").toString();
int count = 0;
try {
Log.d("", urlDownload);
URL url = new URL(urlDownload);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
// Get File Name from URL
String fileName = urlDownload.substring(urlDownload.lastIndexOf('/')+1, urlDownload.length() );
//Environment.getExternalStorageDirectory().getPath()
Log.d("", fileName);
OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory().getPath()+"/"+fileName);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
Status = (int)((total*100)/lenghtOfFile);
output.write(data, 0, count);
// Update ProgressBar
handler.post(new Runnable() {
public void run() {
updateStatus(position,Status);
}
});
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("log_tag", "eer "+e.toString());
}
}
};
new Thread(runnable).start();
}
好吧,我正在尝试从服务器下载Excel文件.每个文件都显示为列表,当我单击该列表时,将下载该文件.但是每次我单击文件时.它会在我给你的log.cat上输出错误
Well, im trying to download an excel file from the server. Each file is displayed as list on which when i click it, it will be downloaded. But Everytime i clicked the file. it outputs the error on the log.cat i gave you
推荐答案
如果您使用的是模拟器
,则需要在您的计算机中设置特定的 sd卡值
模拟器,以便您可以测试和下载文件.
If you're using an emulator
, you need to set a specific sd card value
in your emulator so that you can test and download the file.
如果您使用的是设备,请先安装apk,然后尝试下载该文件.并确保设备具有存储卡
或 sd卡
If you're using a device then install the apk and then try to download the file. And make sure that the device has a memory card
or sd card
因此,您确实需要 sdcard/memcard
来下载文件.
So you really need sdcard/memcard
to download the file.
这篇关于始终在Android中拒绝FileNotFoundException权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!