总是在android中FileNotFoundException权限被拒绝
为什么我总是得到这个错误FileNotFoundException权限被拒绝? 代码是顺利的,但是当我点击一个文件下载,它不会被下载。 请帮帮我。 即时通讯新的这一点
这是我的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"/>
这是我的下载function
//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的错误
如果您正在使用emulator
,则需要在emulator
中设置特定的sd card value
,以便testing和下载文件。
如果您使用的是设备,请安装apk,然后尝试下载该文件。 确保设备有memory card
或sd card
所以你真的需要sdcard/memcard
来下载文件。