简体   繁体   中英

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. I'm getting this error, Exception 'open failed: EACCES (Permission denied)' on Android

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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