我需要在写入整个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());
}
上一篇:不能隐式转换类型'布尔?以“布尔”。一个显式转换存在(是否缺少强制转换?)布尔、存在、类型、隐式
下一篇:机器人imageview.setBackgroundResource()不工作机器人、工作、imageview、setBackgroundResource