3
我知道这个问题还有很多其他帖子,但没有一个能解决我的问题。我正在尝试在Enviroment.DIRECTORY_DOWNLOADS
上创建一个文件,将该文件发送给该文件,然后将其删除。但是,当我初始化文件输出流fos = new FileOutputStream(file);
时出现错误。打开失败:ENOENT(没有这样的文件或目录),即使有权限
我得到的错误是:
java.io.FileNotFoundException: /CheckListReport_2015_07_19.txt: open failed: ENOENT (No such file or directory)
在我的清单我有<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
外的应用程序标签
下面的代码如下:
String report = new SimpleDateFormat("yyyy_MM_dd").format(Calendar.getInstance().getTime());
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS);
File file = new File(path, "CheckListReport_" + report + ".txt");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
String lineToWrite;
for (Map.Entry entry : CheckboxHandler.data.entrySet()) {
lineToWrite = entry.getKey() + ", " + entry.getValue() + "\n";
fos.write(lineToWrite.getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
String subject = "CheckListReport_" + report + ".txt";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(new File(path, "CheckListReport_" + report + ".txt").toString()));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
file.delete();
我仍然得到同样的错误与该行 – Brejuro
@Brejuro尝试这个编辑的代码。 –
感谢您的回复,我用当前的代码编辑了我的帖子。当我点击发送它说'不幸的Gmail已经停止' – Brejuro