class my_thread extends Thread{ public void run(){
// 读取Logcat内容
try{
// 读取Logcat,写入log.txt
File file = new File("/sdcard/log.txt");
// 输出流
FileOutputStream fos = new FileOutputStream(file);
// 清空Logcat缓冲区
Runtime.getRuntime().exec("logcat -c");
// 获取Logcat所对应的进程
Process process = Runtime.getRuntime().exec("logcat");
// 获取该对象的输出流
InputStream is = process.getInputStream();
// 创建一个缓冲区,将Logcat中对应的数据存入缓存中
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// 接收从缓冲区中读到的数据
String result = null;
// 循环读取Logcat对应的缓冲中的日志信息
while ((result = reader.readLine()) != null){
// 判断服务是否处于开启状态,如果关闭,需要将流对象关闭,
// 同时结束当前的onCreate方法(结束子线程)
if (!system_service.is_run){
// 关流
fos.close();
// 结束当前方法的执行,目的是要结束子线程的执行
return;
}
// 判断Logcat中是否包含"I/ActivityManager",
// 如果包含,则将其写入到文件中
// if (result.contains("I/ActivityManager")){
fos.write(result.getBytes());
fos.flush();
// }
// 使用完流对象后,关闭流
fos.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}应该是将logcat的内容写到/sdcard/log.txt,运行后发现/sdcard/log.txt一片空白,什么都没有。
调试发现,运行到while ((result = reader.readLine()) != null)是就直接跳出循环了,就是说while循环根本没有执行,但是在DOS窗口输入adb logcat,又有很多行信息。
这是怎么回事呢?
// 读取Logcat内容
try{
// 读取Logcat,写入log.txt
File file = new File("/sdcard/log.txt");
// 输出流
FileOutputStream fos = new FileOutputStream(file);
// 清空Logcat缓冲区
Runtime.getRuntime().exec("logcat -c");
// 获取Logcat所对应的进程
Process process = Runtime.getRuntime().exec("logcat");
// 获取该对象的输出流
InputStream is = process.getInputStream();
// 创建一个缓冲区,将Logcat中对应的数据存入缓存中
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
// 接收从缓冲区中读到的数据
String result = null;
// 循环读取Logcat对应的缓冲中的日志信息
while ((result = reader.readLine()) != null){
// 判断服务是否处于开启状态,如果关闭,需要将流对象关闭,
// 同时结束当前的onCreate方法(结束子线程)
if (!system_service.is_run){
// 关流
fos.close();
// 结束当前方法的执行,目的是要结束子线程的执行
return;
}
// 判断Logcat中是否包含"I/ActivityManager",
// 如果包含,则将其写入到文件中
// if (result.contains("I/ActivityManager")){
fos.write(result.getBytes());
fos.flush();
// }
// 使用完流对象后,关闭流
fos.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}应该是将logcat的内容写到/sdcard/log.txt,运行后发现/sdcard/log.txt一片空白,什么都没有。
调试发现,运行到while ((result = reader.readLine()) != null)是就直接跳出循环了,就是说while循环根本没有执行,但是在DOS窗口输入adb logcat,又有很多行信息。
这是怎么回事呢?
解决方案 »
- arduino的开发环境的问题
- 求大神帮忙解释android中声音感应的代码(作为初学者的菜鸟表示看不懂!)
- 视频分辨率获取MediaMetadataRetriever
- servlet 监听问题请教
- Android porting 调试的相关问题
- 安卓程序在模拟机上停止运行是怎么回事
- 拍照后获取不了图片!
- 创建新的Android项目,Eclipse自动创建的appcompat内容
- android多任务下载,并实时显示在多个进度条问题
- 关于httpclient http请求改https请求
- GitHub里ActiveAndroid 项目 用于SQLite的ORM框架 表自动创建问题
- 请问 怎样 去 控制 双卡的 手机去用 C,网 或G 网拨号?
if (socket.isConnected()) {
if (!socket.isInputShutdown()) {
if ((result= in.readLine()) != null) {
result+= "\n";
} else {
}
}
}
}