public void save(){
Log.e(TAG, "begin to save");
String data="12345678";
String path = "/proc/iflyTek/iflyTek";
File mFile = new File(path);
try {
Log.e(TAG, "begin to try");
FileOutputStream mFileOutputStream = new FileOutputStream(mFile);
Log.e(TAG, "mFileOutputStream");
OutputStreamWriter mOutputStreamWriter = new OutputStreamWriter(mFileOutputStream);
Log.e(TAG, "mOutputStreamWriter");
mOutputStreamWriter.write(data);
Log.e(TAG, "mOutputStreamWriter.write()");
mOutputStreamWriter.close();
Log.e(TAG, "save success");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "e.printStackTrace()"+e);
}
}
public void readSavedDate() throws IOException{
Log.e(TAG, "begin to readSavedDate");
String path = "/proc/iflyTek/iflyTek";
FileReader fRe = null;
BufferedReader bRe = null;
StringBuilder content=new StringBuilder();
try {
fRe = new FileReader(path);
bRe = new BufferedReader(fRe);
String line=null;
while((line=bRe.readLine())!=null){
content.append(line);
}
String getData = null;
getData=content.toString();
Log.e(TAG, "read success and getData is "+getData);
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
if(fRe!=null){
try {
fRe.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
java写入和读取文件
最新推荐文章于 2023-07-09 18:12:57 发布