Android Log write(String path, String log)

Here you can find the source of write(String path, String log)

Description

write

Declaration

public static void write(String path, String log) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import android.content.Context;

public class Main {
    public static void write(Context context, String log) {
        try {/*  w  w  w . j  a  va2 s . c o  m*/
            File file = new File("/mnt/sdcard/" + context.getPackageName()
                    + ".test.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file);
            fw.write(log);
            fw.flush();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write(String path, String log) {
        try {
            File file = new File(path);
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(path);
            fw.write(log);
            fw.flush();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void write(String log) {
        write("/mnt/sdcard/test.txt", log);
    }
}

Related

  1. logw(String msg)
  2. log(String text)
  3. logError(Object errorClass, String msg, Exception e)
  4. logError(String errorClass, String msg, Exception e)
  5. e(Class clazz, String message)
  6. LogE(String tag, String message)
  7. debug(Object msg)
  8. debug(Object msg, Object msg2)
  9. debug(Throwable e)