Android(安卓)文件存储的简单实现
文件写入
FileOutputStream out = null ;
BufferedWriter writer = null ;
try {
out = openFileOutput("data", Activity.MODE_PRIVATE);
writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write(inputText);
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(writer != null ){
writer.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
文件读取
private String load(String fileName){
FileInputStream in = null;
BufferedReader reader = null;
StringBuilder content = new StringBuilder();
try {
in = openFileInput(fileName);
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while( (line = reader.readLine()) != null ){
content.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(reader != null){
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return content.toString();
}
内容参照《第一行代码》
更多相关文章
- android 反编译入门
- 从android 里面读取配置文件
- Android写Logcat文件保存到SD卡
- Android(安卓)Studio 使用NDK编译时常见的问题
- android 设置设置中Region & Time Zone
- android中使用HTTP协议和TCP协议实现上传文件
- Android(安卓)Shell Cmd
- Android(安卓)用户反馈界面的实现
- Android全屏设置的两种方式