简体   繁体   English

打开失败:Android中的EACCES(权限被拒绝)

[英]Open failed: EACCES (Permission denied) in Android

I found a code and edited a bit according to my application. 我找到了一个代码,并根据我的应用程序进行了一些编辑。 It is about writing a text to txt on Android in bytes. 它是关于在Android上以字节为单位向txt写入文本。 I'm getting this error, Exception 'open failed: EACCES (Permission denied)' on Android 我收到此错误, Android上的异常“打开失败:EACCES(权限被拒绝)”

As stated in the link above, I changed its place where user-permission related to write_external_storage is located in my Android Manifest file. 如上面的链接所述,我更改了Android Manifest文件中与write_external_storage相关的用户权限所在的位置。 However, in that file, I received " tag appears after tag" Warning leading me to get the same error again. 但是,在该文件中,我收到“标签后出现标签”警告,导致我再次遇到相同的错误。

Thank you in advance 先感谢您

 if (response.equals("tag OK " + param[2]
                + " authenticated (Success)")) {

             mySuccessfulLogin = param[0] + "\n"
                    + param[1] + "\n" + param[2]
                    + "\n" + newpassword;

            myDirectory = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+"Users/macbookpro/Documents/CS328/Android_IMAP";

            File custdir = new File(myDirectory);
            if(!custdir.exists())
                {
                    custdir.mkdirs();

                }

            File savedir=new File(custdir.getAbsolutePath());
            File file = new File(savedir, "LastLogin");

            if(file.exists())
                 {
               file.delete();
                 }

            FileOutputStream fos;

            byte[] data = mySuccessfulLogin.getBytes();

            try {

                fos = new FileOutputStream(file);
                fos.write(data);
                fos.flush();
                fos.close();
                               // Toast.makeText(, "File Saved", Toast.LENGTH_LONG).show();

             } catch (FileNotFoundException e) {
                                //Toast.makeText(getBaseContext(), "Error File Not Found", Toast.LENGTH_LONG).show();
               Log.e("fnf", ""+e.getMessage());
                                // handle exception
              } catch (IOException e) {
                                // handle exception
                               // Toast.makeText(getBaseContext(), "Error IO Exception", Toast.LENGTH_LONG).show();
              }

        }

You need this permission in your manifest 您需要在清单中获得此许可

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

before the application tag. 在应用标签之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM