package com.example.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import android.content.Context;
public class Utils1 {
public static boolean saveUserInfo(Context context, String number, String password) {
File file = new File(context.getCacheDir(), "it.txt");
try {
FileOutputStream fos = new FileOutputStream(file);
String text = number + "####" + password;
try {
fos.write(text.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
public static String getUserInfo(Context context) {
try {
File file = new File(context.getCacheDir(), "it.txt");
//字节流
FileInputStream fis = new FileInputStream(file);
//转换流
InputStreamReader isr = new InputStreamReader(fis);
//字符流
BufferedReader br = new BufferedReader(isr);
try {
String rsrult = br.readLine();
br.close();
isr.close();
fis.close();
return rsrult;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}