【问题标题】:Always FileNotFoundException Permission Denied in android总是在android中拒绝FileNotFoundException权限
【发布时间】:2015-06-01 11:50:07
【问题描述】:

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

这是我的日志

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 上输出错误

【问题讨论】:

  • 你的问题不清楚,你说你不能从某个地方下载文件,但是根据你的logcat,它看起来像权限问题,或者文件被读保护。你想做什么?
  • 我已经更新了我的代码。

标签: android excel download server


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-17
    • 2023-03-16
    相关资源
    最近更新 更多