我是靠谱客的博主 平淡烤鸡,最近开发中收集的这篇文章主要介绍android log4j 将日志自动发送到邮箱,Android写入日志文本文件,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Android写入日志文本文件

我正在尝试使用Mine的代码将日志写入Android文件上的自定义Log.txt文件,但此方法创建文件但不包含任何内容。基本上我想读取文件的先前内容,然后用现有内容附加我的数据。

守则如下:public static void write(String str)

{

InputStream fileInputStream = null;

FileOutputStream fileOutpurStream = null;

try

{

fileInputStream = new FileInputStream(file);

fileOutpurStream = new FileOutputStream(file);

if(file.exists())

{

int ch = 0;

int current = 0;

StringBuffer buffer = new StringBuffer();

while((ch = fileInputStream.read()) != -1)

{

buffer.append((char) ch);

current++;

}

byte data[]=new byte[(int)file.length()];

fileInputStream.read(data);

fileOutpurStream.write(data);

fileOutpurStream.write(str.getBytes(),0,str.getBytes().length);

fileOutpurStream.flush();

}

else

{

file.createNewFile();

fileOutpurStream.write(str.getBytes(),0,str.getBytes().length);

fileOutpurStream.flush();

}

}

catch(Exception e)

{

e.printStackTrace();

}

finally

{

try

{

fileInputStream.close();

fileOutpurStream.flush();

fileOutpurStream.close();

fileOutpurStream = null;

fileInputStream = null;

}

catch (IOException e)

{

// TODO Auto-generated catch block

e.printStackTrace();

}

}

最后

以上就是平淡烤鸡为你收集整理的android log4j 将日志自动发送到邮箱,Android写入日志文本文件的全部内容,希望文章能够帮你解决android log4j 将日志自动发送到邮箱,Android写入日志文本文件所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部