字符串只要数字和生成外部 log file

来源:互联网 时间:1970-01-01

在电话中 经常竖线123-245-36 或者123.25.6 去掉这些myString.replaceAll("/D", "");

import android.os.Environment;
import android.util.Log;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;

FileHandler fh=null;
String name;
if ( 0 == Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED))
name = Environment.getExternalStorageDirectory().getAbsolutePath();
else
name = Environment.getDataDirectory().getAbsolutePath();

name += "/mylogfile.log";

try {
fh = new FileHandler(name, 256*1024, 1, true);
fh.setFormatter(new SimpleFormatter());
fh.publish(new LogRecord(level, tag+": "+msg));
} catch (Exception e)
{
Log.e("MyLog", "FileHandler exception", e);
return;
}finally{
if (fh != null)
fh.close();
}

当然这不是系统的logcat


相关阅读:
Top