Android存取txt
/** 取SD卡路径 **/
private String getSDPath() {
File sdDir = null;
boolean sdCardExist = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
// 判断sd卡是否存在
if (sdCardExist) {
sdDir = Environment.getExternalStorageDirectory();
// 获取根目录
}
if (sdDir != null) {
return sdDir.toString();
} else {
return "";
}
}
/** 保存密码文件路径 **/
private String getDirectory() {
String dir = getSDPath() + "/" + "QQTSAVE";
File file = new File(dir);
if (!file.exists()) {
try {
file.mkdirs();
} catch (Exception e) {
e.printStackTrace();
}
}
return dir;
}
private void toSave(String user, String password) {
File file = new File(getDirectory() + "/" + "us.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
FileWriter fw = new FileWriter(file);
fw.write(user + "asd" + password);
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String Read() {
String sb = "";
BufferedReader br;
try {
br = new BufferedReader(new FileReader(getDirectory() + "/" + "us.txt"));
String line = "";
while ((line = br.readLine()) != null) {
sb=line;
}
br.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("--------------", sb);
return sb;
}
public void deleteSave(String user){
File file = new File(getDirectory() + "/" + "us.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
FileWriter fw = new FileWriter(file);
fw.write(user+"null");
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
更多相关文章
- Pycharm安装PyQt5的详细教程
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- Android更新UI的五种方式
- android 之simpleAdapter详解
- android监听当前应用
- 获取Android(安卓)Device的信息
- android apk 安装路径 包名解析 覆盖安装等问题
- Android中获取应用程序(包)的信息-----PackageManager的使用(一)
- 遍历android根目录的简单资源查看器