您的位置:首页 > 其它

文件读写,字符串持久化

2013-12-12 18:23 274 查看
public String readFile2String(String fileName) {
StringBuffer sb = new StringBuffer();
try {
FileInputStream fin = new FileInputStream(fileName);
byte[] buffer = new byte[1024*4];
int len = 0 ;
while((len=fin.read(buffer))!=-1){
sb.append(EncodingUtils.getString(buffer, 0, len,"UTF-8"));
}
fin.close();
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}

private void writeString2File(String jsondata , String filename) {
try {

FileOutputStream fos = new FileOutputStream(filename);
fos.write(jsondata.getBytes("UTF-8"));
fos.close();
} catch (Exception e) {
e.printStackTrace();
Log.e("",
"file e :" + e.toString());
}
}
本文出自 “绝对领域” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: