如何写全的logcat到SD卡? [英] How to write entire Logcat in to sdcard?

查看:108
本文介绍了如何写全的logcat到SD卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在写入整个logcat中到SD卡未过滤的LogCat中。所以,我试图做这样

I need to write entire Logcat in to sdcard not the filtered Logcat. So I tried doing this way

String[] cmd  ={"/system/bin/logcat " +"-f"+" /sdcard/d.txt"};
    Log.d("NTK","cmd string"+cmd);
    Runtime run = Runtime.getRuntime();

    Process pr;
    try {
        pr = run.exec(cmd);

    pr.waitFor();
    BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line = "";
    while ((line=buf.readLine())!=null) {
        System.out.println(line);
        Log.i(NTL, "lines"+line);
    }
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我所给出的清单文件中的所有权限了。

I have given all permissions in manifest file too.

不能够到SD卡写入logcat中。

Not able to write logcat in to sdcard.

推荐答案

您可以 教程读取日志。而对于写入日志文件中,你可以简单地使用的FileWriter 放弃与文件名的文件的路径。

You can have this Tutorial for Reading the Logs. And for writing the logs in the file you can simply use FileWriter give path of the file with file name.

try {
            File root = Environment.getExternalStorageDirectory();
            if (root.canWrite()) {
                File gpslogfile = new File(root, "log.txt");
                FileWriter gpswriter = new FileWriter(gpslogfile, true);
                BufferedWriter out = new BufferedWriter(gpswriter);
                out.append(DataToWrite);
                out.close();
            }
        } catch (IOException e) {
            Log.d("Log: ", "Could not write file " + e.getMessage());
        }

这篇关于如何写全的logcat到SD卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆