我在创建日志文件时遇到了很多麻烦。它在另一个程序中对我有用,但在这个程序中不起作用,我快疯了,因为我写的完全一样......我想将 logcat 存储在 Android 设备 SDCard 中的 .txt 文件中。它创建文件,但它是空的。
编码:
public void logging() throws IOException{
Log.i(TAG, "On logging");
String listLogs = "dalvikm:I System.err:I AndroidRuntime:I NetworkInfo:I ActivityManager:I ";
File filename = new File(Environment.getExternalStorageDirectory()+"/logEth.txt");
try {
filename.createNewFile();
String cmd = "logcat -d -v threadtime -f "+ filename.getAbsolutePath() +" "+ listLogs +" *:S";
Runtime.getRuntime().exec(cmd);
Log.d(TAG, "logs written");
} catch (IOException e) {
Log.e(TAG, " on creating logging ", e);
throw new IOException(TAG+" error creating the logs. ", e);
}
}
太感谢了!