public static boolean OutLogFile = true;// 输出log信息到文件

/** 输出log信息到文件中 */

public static String FileLog(String info)

{

if (OutLogFile)

{

String crashPath = "/sdcard/FileLog/Log/";

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String date = formatter.format(new Date());

DateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");

String time = formatter2.format(new Date()) + " ";

String fileName = "log-" + date + ".txt";

info = "\r\n" + time + info;

try

{

if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))

{

// String path = "/sdcard/com.hm.pay.demo/crash/";

File dir = new File(crashPath);

if (!dir.exists())

{

dir.mkdirs();

}

FileOutputStream fos = new FileOutputStream(crashPath + fileName, true);

fos.write(info.getBytes());

fos.close();

}

}

catch (Exception e)

{

Log.e(TAG, "an error occured while writing file log...", e);

}

return crashPath + fileName;

}

else return "";

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐