令人讨厌的是,我让下面的代码创建并写入 sdcard 上的文件,然后继续开发更多代码。但是我必须改变一些东西,因为现在它不起作用。
这是漫长而烦人的一天,所以我想知道是否有人可以指出我所犯的简单错误。
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy / hh-mm-ss");
Date curDate = new Date();
String stringDate = sdf.format(curDate);
String resultLogFile = "logFile " + stringDate;
File newFile = new File("sdcard/" + (resultLogFile));
if (!newFile.exists()) {
try {
newFile.createNewFile();
}
catch (IOException e) {
e.printStackTrace();
}
}
try {
BufferedWriter buf = new BufferedWriter(new FileWriter(newFile, true));
buf.append(writeToFileString);
buf.newLine();
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
这是控制台:
09-19 17:58:16.270: W/System.err(10411): java.io.IOException: open failed: ENOENT (No such file or directory)
09-19 17:58:16.275: W/System.err(10411): at java.io.File.createNewFile(File.java:940)
09-19 17:58:16.275: W/System.err(10411): at android.Maps.GeneticAlgorithm3.shufflePerm3(GeneticAlgorithm3.java:192)
09-19 17:58:16.275: W/System.err(10411): at android.Maps.HomeScreen$6.onClick(HomeScreen.java:334)
09-19 17:58:16.275: W/System.err(10411): at android.view.View.performClick(View.java:4084)
09-19 17:58:16.275: W/System.err(10411): at android.view.View$PerformClick.run(View.java:16966)
09-19 17:58:16.275: W/System.err(10411): at android.os.Handler.handleCallback(Handler.java:615)
09-19 17:58:16.275: W/System.err(10411): at android.os.Handler.dispatchMessage(Handler.java:92)
09-19 17:58:16.275: W/System.err(10411): at android.os.Looper.loop(Looper.java:137)
09-19 17:58:16.275: W/System.err(10411): at android.app.ActivityThread.main(ActivityThread.java:4896)