我有一个收集加速度计数据的应用程序,然后我希望将这些数据写入CSV文件并通过电子邮件发送给用户。尝试发送电子邮件时,会记录以下错误:
6-20 17:09:00.550 3764-4558/? E/RequestController﹕ IOException
java.io.FileNotFoundException: /data/data/com.htc.android.mail/app_mail/Download/Walk Data-20150620-170859.csv: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:406)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at com.htc.android.mail.server.SmtpServer.includeAttach(SmtpServer.java:948)
at com.htc.android.mail.server.SmtpServer.issueBody(SmtpServer.java:347)
at com.htc.android.mail.server.SmtpServer.sendMail(SmtpServer.java:153)
at com.htc.android.mail.RequestController$SmtpThread.run(RequestController.java:2016)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:390)
以下是onClick方法的代码,其中编写了CSV并且电子邮件正在尝试发送:
public void onClick(View v) {
switch (v.getId()) {
case R.id.enrolBtn:
choice = 1;
Toast.makeText(this, "Enrolment Mode Selected", Toast.LENGTH_SHORT).show();
break;
case R.id.authBtn:
choice = 2;
Toast.makeText(this, "Authentication Service Starting", Toast.LENGTH_SHORT).show();
break;
case R.id.sendBtn:
choice = 3;
String fileName = "Walk Data.csv";
String baseDir = getFilesDir() + "/" + fileName;
File f = new File(baseDir);
FileOutputStream out = null;
try {
out = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
out.write(walkData.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
android.net.Uri u1 = Uri.fromFile(f);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, u1);
sendIntent.setType("text/html");
startActivity(sendIntent);
break;
以下是加速度计数据收集并存储在walkData字符串中的代码:
public void onSensorChanged(SensorEvent event) {
float x = event.values[0];
ArrayList<Float> enrolAcc = new ArrayList<>();
ArrayList<Float> authAcc = new ArrayList<>();
TextView textEnrol = (TextView) findViewById(R.id.textView);
if (choice == 1) {
mPreviousAcc = mCurrentAcc;
mCurrentAcc = (float) Math.sqrt((double) (x * x));
float delta = mCurrentAcc - mPreviousAcc;
mDiffAcc = mDiffAcc * 0.9f + delta;
if (enrolAcc.size() < 100) {
enrolAcc.add(x);
} else {
enrolAcc.remove(0);
enrolAcc.add(x);
}
walkData = enrolAcc.toString();
textEnrol.setText(walkData);
}
提前感谢您的帮助。
答案 0 :(得分:0)
因此,正如异常所说,它试图在Type
文件夹中查找文件。而文件不存在。如果您想创建文件,可以尝试this:
/data/data/com.htc.android.mail/app_mail/Download/