2014-11-14 128 views
0

我找到了一个代码并根据我的应用程序编辑了一下。它是以字节为单位向Android上的txt写文本。我得到这个错误,Exception 'open failed: EACCES (Permission denied)' on Android开放失败:Android中的EACCES(权限被拒绝)

正如上面的链接所述,我改变了它的地方,其中与write_external_storage相关的用户权限位于我的Android Manifest文件中。但是,在该文件中,我收到“标签出现在标签后面”警告,导致我再次得到相同的错误。

预先感谢您

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(); 
       } 

     } 
+0

请发布您的日志请 – Lukos 2014-11-14 16:21:44

回答

1

你在你的清单

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

之前的应用程序标记需要这个权限。

+0

如果您有WRITE_EXTERNAL_STORAGE权限,您不需要READ_EXTERNAL_STORAGE,但是,他确实需要WRITE_EXTERNAL_STORAGE – Guardanis 2014-11-14 15:50:39

+0

我已经完成了您之前告诉我的任何内容。那时,它没有工作。但是这一次它可以工作,但是我无法在我的目录中找到它。你们有什么想法吗? @Guardanis – 2014-11-14 16:37:33

+0

找到究竟是什么? – Lukos 2014-11-14 17:12:13

相关问题