android 中始终拒绝 FileNotFoundException 权限

Always FileNotFoundException Permission Denied in android

为什么我总是收到此错误 FileNotFoundException Permission Denied?代码进行得很顺利,但是当我单击要下载的文件时,它不会被下载。请帮我。我是新手

这是我的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

上输出错误

如果您使用的是 emulator,您需要在模拟器中设置一个特定的 sd card value,以便您可以测试和下载文件。

如果您使用的是设备,请安装 apk,然后尝试下载文件。并确保设备具有 memory cardsd card

所以你真的需要 sdcard/memcard 来下载文件。