gpt4 book ai didi

java - 为什么即使我的文件位于正确的位置,我也会收到 filenotfound 异常?

转载 作者:行者123 更新时间:2023-11-29 23:13:16 24 4
gpt4 key购买 nike

我的以下代码以前可以工作。但是在我最近格式化了我的手机之后,它就不再工作了。请帮我解决这个问题。

设置路径的代码是:

 path = Environment.getExternalStorageDirectory().getPath() + "/IMG-20190324-WA0000.jpg";
try {
m.addAttachment(path);

if(m.send()) {
Toast.makeText(context, "Email was sent successfully :)", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Email was not sent :(", Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
//Toast.makeText(context, "There was a problem sending the email.", Toast.LENGTH_LONG).show();
Log.e("MailApp", "Could not send email", e);
}

我收到以下错误:

E/MailApp: Could not send email
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.FileNotFoundException: /storage/emulated/0/IMG-20190324-WA0000.jpg: open failed: EACCES (Permission denied)

我的 list 权限:

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

文件和之前一样在准确的位置,那为什么代码不能读取呢?

The file location screenshot :

最佳答案

我所要做的就是转到设备设置 -> 应用程序 -> 我的应用程序 -> 打开存储权限。感谢@Pklumpp 帮助我走出困境

关于java - 为什么即使我的文件位于正确的位置,我也会收到 filenotfound 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55731614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com