private String readTxt(String filepath){
File file = new File(filepath);
String result = "";
if (file.exists()) {
try {
InputStream in = new BufferedInputStream(new FileInputStream(file));
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer();
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
result = sb.toString();
br.close();
in.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
return result;
}
private void save2txt(String msg, String path){
if (null == msg || TextUtils.isEmpty(msg)) {
return;
}
File file = new File(path);
try {
if (!file.exists()) {
file.createNewFile();
}
RandomAccessFile rf = new RandomAccessFile(file, "rw");
long len = rf.length();
rf.seek(len);
rf.writeBytes(msg + "\n");
rf.close();
} catch (Exception e) {
// TODO: handle exception
}
}
Android读写SD卡中的txt文件
最新推荐文章于 2021-12-24 15:53:55 发布