文件读写,字符串持久化
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());
}
}
本文出自 “绝对领域” 博客,转载请与作者联系!
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());
}
}
本文出自 “绝对领域” 博客,转载请与作者联系!
相关文章推荐
- Object-c学习之路六(oc字符串文件读写)
- [C/C++标准库]_[初级]_[读写中文路径的文件--写入unicode字符串]
- Java基本功练习十四(字符串和文本IO【文件读写数据、字符串生成器、String类方法、相关技巧】)
- 利用数据库存储文本文件、图像文件需要的字符串读写方法备忘
- Lua杂记一:文件读写、table库、字符串库
- 文件操作《3》字符串读写
- [JAVA]用JAVA文件读写操作截取文件中所有以x开头y结尾的字符串
- Lua杂记一:文件读写、table库、字符串库
- python读写文件,分析字符串及读取目录下文件名的实践
- 逐行读写字符串数组到文本txt文件
- Objective-C 【从文件中读写字符串(直接读写/通过NSURL读写)】
- C文件之二 字符串读写
- php语法基础(一)- 变量、常变量、函数、分支和循环、字符串、数组、类、时间、日期、包含文件、文件及图片读写等
- 20140310 字符串比较 文件读写
- 常用方法归档-获取<日期、字符串倒写、随机数、读写文件>
- Objective-C 【从文件中读写字符串(直接读写/通过NSURL读写)】
- iOS数据持久化文件读写之偏好设置
- Java中文件的读写及流向字符串的转化
- 文件读写函数 -- 字符串读写
- 文件读写及字符串与整数的相互转换