//读文件,此处以文本文件为例,也可以写入二进制文件
private void writeLog(String sMsg) {
try {
FileOutputStream out=this.openFileOutput("myLog",MODE_APPEND);
out.write(sMsg.getBytes());
out.close();
} catch (Exception e){
e.printStackTrace();
}
}
private String readLog(){
String sText="";
try {
FileInputStream in=this.openFileInput("myLog");
byte[] b= new byte[1024];
in.read(b); //只读一次 1MKB的内容,如果希望全部读完,可以改成循环去读 while (in.read(b)>-1)
sText = new String(b,"UTF-8");
in.close();
} catch (Exception e){
e.printStackTrace();
}
return sText;
}