我目前正在尝试将当前时间粘贴到 Android 应用程序的文件中。代码如下所示,但未创建文件。我已启用我的应用程序通过清单在 SD 卡上写入的权限。有任何想法吗?
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
try {
File myFile = new File("/sdcard/mysdfile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
SimpleDateFormat dF = new SimpleDateFormat("HHMMSS");
StringBuilder current = new StringBuilder(dF.format(today));
myOutWriter.append(current);
myOutWriter.close();
fOut.close();
}