防丢App记录(2)--将序列号通过文件存储

来源:互联网 发布:360手机数据恢复软件 编辑:程序博客网 时间:2024/06/13 15:36

存String数
private void save(String te1) {
try {
mFileOutputStream=openFileOutput(“simid”, Context.MODE_PRIVATE);
writer =new BufferedWriter(new OutputStreamWriter(mFileOutputStream));
writer.write(te1);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(writer!=null){
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
取出来
public String load(){
FileInputStream in=null;
BufferedReader reader=null;
StringBuilder content=new StringBuilder();
try {
in=openFileInput(“simid”);
reader=new BufferedReader(new InputStreamReader(in));
String line=null;
while((line=reader.readLine())!=null){
content.append(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(reader!=null){
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();

            }        }    }    return  content.toString();}
0 0