package com.mapbar.android.obd.util;import android.os.Environment;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/** * Created by sunxx on 2017/12/14. * 日志文件 */public  class Logs {    public static String TIRE_TAG="1";    public static String PHY_TAG="2";    public static String STATE_TAG="3";    public static boolean isDebug=false;    public final static String FILE_PATH = "/aa/bb";//包名文件夹    public static File file;    public  static FileOutputStream fos;    public static Logs logs;    public Logs() {    }    public static synchronized Logs getInstance(){        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + FILE_PATH + "/log/a.txt";        try {                file = new File(path);                                  fos = new FileOutputStream(file, true);                   } catch (FileNotFoundException e) {            e.printStackTrace();        }        if (logs==null){            logs=new Logs();        }        return logs;    }    //写入日志文件    public  void writeEvent(String tag,String msg){        if (!isDebug){            return;        }        if (fos==null){            return;        }        try        {            fos.write((TimeFormatUtil.formatStrLong(System.currentTimeMillis())+"|"+tag+"|"+msg+"\r").getBytes());            fos.flush();            fos.close();        }        catch (FileNotFoundException e)        {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }    }}

更多相关文章

  1. android 调用第三方软件打开pdf文件
  2. android读取日志demo
  3. Android(安卓)通过HTTP POST 上传图片文件
  4. Android(安卓)studio 点击按钮 改变viewtext 文字的颜色
  5. Android代码混淆官方实现方法
  6. android获取指定路径下目录文件
  7. Android(安卓)文件读写的例子
  8. android:xml解析
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android(安卓)目录
  2. android使用ffmpeg的实例程序
  3. android之activity平滑水平切换动画
  4. Android(安卓)SwipeLayout实现界面滑动布
  5. Android(摩托)HttpURLConnection getInpu
  6. Android(安卓)MVPR 架构模式-Part1
  7. Android-Room自定义类型
  8. [Android(安卓)Studio] 关于*.SO压缩问题
  9. Android控件自定义形状
  10. Android(安卓)Audio代码分析5 - 函数getA