2014-11-14 127 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

相關問題