您的位置:首页 > 移动开发 > Android开发

Android文本读写

2015-12-31 15:01 447 查看
//写文件操作
public void writeFileData(String fileName, String message){
try{
FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);
byte[] bytes = message.getBytes();
fout.write(bytes);
fout.close();
}catch (Exception e){
e.printStackTrace();
}
}

//读文件操作
public String readFileData(String fileName){
String res = "";
try {
FileInputStream fin = openFileInput(fileName);
int length = fin.available();
byte[] buffer = new byte[length];
fin.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");
fin.close();
} catch (Exception e) {
e.printStackTrace();
}
return res;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: