打开失败:Android中的EACCES(权限被拒绝)
我找到了一个代码,并根据我的应用程序进行了编辑。它是关于在Android上以字节为单位将文本写入txt。我得到了这个错误 正如上面的链接所述,我更改了与write_external_存储相关的用户权限在我的Android清单文件中的位置。但是,在该文件中,我收到了“标记出现在标记之后”警告,导致我再次出现相同的错误 先谢谢你打开失败:Android中的EACCES(权限被拒绝),android,permission-denied,read-write,Android,Permission Denied,Read Write,我找到了一个代码,并根据我的应用程序进行了编辑。它是关于在Android上以字节为单位将文本写入txt。我得到了这个错误 正如上面的链接所述,我更改了与write_external_存储相关的用户权限在我的Android清单文件中的位置。但是,在该文件中,我收到了“标记出现在标记之后”警告,导致我再次出现相同的错误 先谢谢你 if (response.equals("tag OK " + param[2] + " authenticated (Success)"
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();
}
}
您的清单中需要此权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在应用程序标记之前。如果您具有写入外部存储权限,则不需要读取外部存储,但是的,他确实需要写入外部存储。当时,它不起作用。但这一次它工作了,但我在我的目录中找不到它。你们知道吗@Guardanis@Lukos,我的名为LastLogin.txt的txt文件(代码中没有以这种方式显示,但我后来对其进行了更改),如果它是以这种方式存储在目录中的话。它看起来像是在创建后立即删除的。@Lukos,我删除了该部分,但它不起作用。我看不出来。我的意思是因为一个我不知道的原因,那里没有类似的东西。请发布你的日志