当前位置 博文首页 > 赵星海的博客:Android 日志写入文件 最简单实现
?直接复制拿去用,不要和深海客气
/*
*作者:赵星海
*时间:2021/3/13 11:44
*用途:日志写入文件
*/
fun writeLog(text: String?) {
if (!isTest) return//如果是并非测试包 则不进行日志写入
var textR = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date().time) + " " + text + "\r\n"
try {
var fos = FileOutputStream("sdcard/QXH_KJ_LOG.txt", true) //true 末尾
fos.write(textR.toByteArray())
fos.close()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
cs