【发布时间】:2011-06-29 08:18:47
【问题描述】:
我想在我的 java 代码中执行“adb logcat -d time > pathofile\log.txt &”。
我想在我的设备中创建我的 log.txt。
我为此编写了这段代码。
ArrayList<String> commandLine = new ArrayList<String>();
commandLine.add("logcat");
commandLine.add("-d");
commandLine.add("time");
commandLine.add(">");
commandLine.add(getApplicationContext().getFilesDir()
// + "/log.txt"); //already created the file at specified location.
//commandLine.add("&");
Process process = Runtime.getRuntime().exec(commandLine.toArray(new String[0]));
上面的代码没有抛出任何错误,但是我的文件(log.txt)没有用日志语句更新..
请帮助我如何做到这一点,pl。建议是否有任何替代方法可以做到这一点.. 谢谢。
【问题讨论】:
-
您是如何创建文件的?可能是权限问题?
-
我创建了这样的文件: File logf= new File(getApplicationContext().getFilesDir() + "/log.txt"); logf.createNewFile();我可以通过导航到该文件目录来查看 log.txt 文件。所以我认为这不是权限问题。如果它会抛出 IO 异常。
标签: android