/** 取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();
}
}
當前標題:Android存取txt
文章起源:http://vcdvsql.cn/article44/pejgee.html
成都網站建設公司_創新互聯,為您提供網站制作、云服務器、電子商務、關鍵詞優化、自適應網站、網站排名
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯