Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.FileNotFoundException:/storage/emulated/FileTest1.zip:open失败:EACCES(权限被拒绝)_Java_Android - Fatal编程技术网

java.io.FileNotFoundException:/storage/emulated/FileTest1.zip:open失败:EACCES(权限被拒绝)

java.io.FileNotFoundException:/storage/emulated/FileTest1.zip:open失败:EACCES(权限被拒绝),java,android,Java,Android,我试图从服务器下载zip文件时遇到问题。我正在使用intentservice下载该文件,但出现了此异常 java.io.FileNotFoundException: /storage/emulated/FileTest1.zip: open failed: EACCES (Permission denied) 我尝试将文件保存在内部存储器上,而不是SD卡上。 这是我的密码 @Override protected void onHandleIntent(Intent intent) {

我试图从服务器下载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();
    }
}

canI如何修复它?

如果它的android>=6.0,除了清单中的权限之外,您需要在运行时获得用户权限,否则它将无法访问。您可以从设置->应用程序->应用程序管理器->权限手动启用它,这是我认为的一个原因…:)希望它能帮助我手动启用存储权限,但它仍然无法工作尝试此文件File=new File(“/storage/emulated”);Log.e(“Check”,“checking parent exists”+file.exists());在确认父目录存在的任何其他代码行(只是为了确认您可以访问SD卡并且父目录退出)之前,我已经尝试过了,我在logcat:E/Check:checking parent exists true上收到了这条消息。我想这意味着父目录存在,我有访问权。可能用户不允许在/storage/simulated中创建文件。。。取决于您的android版本/设备制造商。。。您可以尝试在那里创建一个文件,使用某种文件资源管理器来检查这个。。。