我想记录我的应用程序活动的一些数据,以便在系统中读取它。数据包括按下按钮时收集的字符串,浮点数等。这样做的最佳方式是什么?
答案 0 :(得分: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的相关问题是here。
答案 1 :(得分:0)