/** 取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();

}

}


更多相关文章

  1. android apk 安装路径 包名解析 覆盖安装等问题
  2. 遍历android根目录的简单资源查看器
  3. android 根据apk文件路径获取图标
  4. android--------根据文件路径使用File类获取文件相关信息
  5. Android获取存储卡路径的方式
  6. 改变android虚拟机的存放路径
  7. Mac修改环境变量路径中带空格的处理
  8. android根据uri或文件绝对路径获取文件基本信息
  9. android 一些路径的标准写法

随机推荐

  1. Mac 版 Chrome 浏览器已支持 Tab Throttl
  2. BAT iOS面试对答题
  3. 金三银四涨薪季,这些面试题你掌握了嘛?
  4. Android TCP Socket通信客户端/服务器端D
  5. CentOS 7部署OpenStack--部署Newtron
  6. php字符串函数
  7. 13:VMware Horizon View 8.0-创建链接克隆
  8. [翻译]微服务设计模式 - 2. 微服务应用模
  9. httpd,tomcat,tomcat-connector下载地址
  10. [翻译]微服务设计模式 - 1. 单体应用模式