• 读取Log日志并打印到sdcard


     1 @SuppressLint("SimpleDateFormat")
     2     private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     3 
     8     public static void LogWrite() {
     9         File file = new File(Constants.APP_PATH_LOG);
    10         if (!file.exists() || !file.isDirectory()) {
    11             file.mkdirs();
    12         }
    13         FileWriter fileWriter;
    14         StringBuilder log;
    15         try {
    16             Process process = Runtime.getRuntime().exec("logcat -d -v time");
    17             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    18 
    19             log = new StringBuilder();
    20             String line;
    21             while ((line = bufferedReader.readLine()) != null) {
    22                 log.append(line);
    23                 log.append("
    ");
    24             }
    25             fileWriter = new FileWriter(Environment.getExternalStorageDirectory() + "/" + “log-” + sdf.format(new Date()).substring(0, 10) + ".txt", true);
    26             fileWriter.write(log.toString());29             fileWriter.flush();
    30             fileWriter.close();
    31             Runtime.getRuntime().exec("logcat -c");32         } catch (IOException e) {
    33 
    34         } catch (OutOfMemoryError e) {
    35             
    36         }
    37        
    67     }
  • 相关阅读:
    初识Java内存结构
    eclipse的安装与配置
    关于android客户端使用ksoap2调用wcf(.svc)的总结
    ie下jpg不显示问题
    Android学习笔记(1)
    HTML标签语义化
    【转】android模拟机不能上网
    WCF IIS 寄宿问题
    C# 参数传递
    Wcf IIS 寄宿
  • 原文地址:https://www.cnblogs.com/slz-bky/p/5881365.html
Copyright © 2020-2023  润新知