我想记录我的应用程序活动的一些数据,以便稍后在系统中读取它。数据包括按下按钮时收集的字符串、浮点数等。做这个的最好方式是什么?
问问题
4095 次
2 回答
1
我最终编写了自己的用于登录设备的函数。
public static BufferedWriter out;
private void createFileOnDevice(Boolean append) throws IOException {
/*
* Function to initially create the log file and it also writes the time of creation to file.
*/
File Root = Environment.getExternalStorageDirectory();
if(Root.canWrite()){
File LogFile = new File(Root, "Log.txt");
FileWriter LogWriter = new FileWriter(LogFile, append);
out = new BufferedWriter(LogWriter);
Date date = new Date();
out.write("Logged at" + String.valueOf(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "\n"));
}
}
public void writeToFile(String message){
try {
out.write(message+"\n");
} catch (IOException e) {
e.printStackTrace();
}
关于 SO 的相关问题在这里。
于 2012-12-07T23:08:54.203 回答
0
于 2011-04-19T09:54:30.537 回答