开发工具:eclipse
开发语言:JAVA
问题:process.destroy()停止之后,logPath.txt里仍旧不断被写入log
伪代码:
String command = adb shell logcat > logPath.txt;
if logkey == true //开始打日志
process = Runtime.getRuntime().exec(command);
else //停止打日志
process.destroy();
解决:使用File创建文件A,将log写入到文件A即可
伪代码:
String command = adb logcat ;
process = Runtime.getRuntime().exec(command);
fwriter = new FileWriter(logFile, true); //创建日志文件
while ((line = input.readLine()) != null) {
if (logKey == false) { //停止打日志
process.destroy();
input.close();
iReader.close(); //关闭内容写入,日志写入就停止了
return;
}
fwriter.write(line + "\r\n"); //开始打日志后,不断写入日志
}