【发布时间】:2016-01-30 20:35:37
【问题描述】:
以下代码正在保存Data.csv文件并通过邮件发送。
我想用当前名称Data.csv 保存文件,然后用其他名称发送这个文件。例如,newname.csv。
代码正在发送newname.csv,但它在设备中保存为Data.csv。关于我做错了什么有什么想法吗?
这是我的代码:
/* Making A New File */
File dir = new File(root.getAbsolutePath() + "/FolderData");
dir.mkdirs();
file = new File(dir, "Data.csv");
out = new FileOutputStream(file); out.write(combinedString.getBytes());
//want to send the file Data.csv that is saved but with other name
File dir = new File(root.getAbsolutePath() + "/DeltioData");
File file2 = new File(dir,"newname.csv");
File Nf=file;
Nf.renameTo(file2);
//
Uri u1 = Uri.fromFile(Nf); Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "any subject");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Text");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@yahoo.gr"});
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/html"); startActivity(sendIntent);
【问题讨论】:
-
你在哪里设置 newname.csv?
-
Data.csv 和 newname.csv 是同一个文件,但我想保存为 data.csv 并作为附件发送,名称为 newname.csv
-
对,但是您要在哪里尝试将 newname.csv 设置为附件?在您的代码中没有尝试实现这一点
-
我为此添加了代码,但不起作用
标签: java android csv sendmail file-rename