Java tutorial
//package com.java2s; import android.util.Log; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { public static final String TAG = "P2PUtils"; public static File writeLog(String root, String filename) { StringBuilder log = new StringBuilder(); try { Process process = Runtime.getRuntime().exec("logcat -d"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = bufferedReader.readLine()) != null) { log.append(line).append("\n"); } } catch (IOException e) { log.append(e.toString()); } File file = new File(root, filename); try { FileOutputStream fOut = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fOut); // Write the string to the file osw.write(log.toString()); osw.flush(); osw.close(); } catch (Exception e) { Log.e(TAG, String.format("Failed to write log to [%s]", file), e); } return file; } }