我的应用程序可以收集一些数据,我只想将这些数据输出到 SD 卡中的 txt 文件中。
出于某种原因,以下代码适用于 Galaxy,但不适用于 Nexus。我猜代码有问题。
//name of the file
String name = "rawData " + year +
"-" + month + "-" + date + "- " + hour + ":" + minute+ ".txt";
// create a folder stores all the txt file.
File root = new File(Environment.getExternalStorageDirectory(), "rawData");
if (!root.exists()) {
root.mkdirs();
}
// creates a file and a file writer
File gpxfile = new File(root, name);
FileWriter writer = null;
try {
writer = new FileWriter(gpxfile);
Log.d(TAG, "The writer is created");
} catch (IOException e1) {
e1.printStackTrace();
}
Log.d(TAG, "Is the writer null? " + writer);
非常感谢!