tv = (TextView)this.findViewById(R.id.tv);
// ds();
//读文件
try {
FileInputStream fis;
fis = openFileInput("file_out.txt");
byte[] buffer = new byte[1024];
fis.read(buffer);
// 对读取的数据进行编码以防止乱码
String fileContent = EncodingUtils.getString(buffer, "UTF-8");
tv.setText(fileContent);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//写文件
public void ds(){
try {
FileOutputStream fos = openFileOutput("file_out.txt",
Context.MODE_PRIVATE);
String inputFileContext = "堆放垃圾思考";
fos.write(inputFileContext.getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// ds();
//读文件
try {
FileInputStream fis;
fis = openFileInput("file_out.txt");
byte[] buffer = new byte[1024];
fis.read(buffer);
// 对读取的数据进行编码以防止乱码
String fileContent = EncodingUtils.getString(buffer, "UTF-8");
tv.setText(fileContent);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//写文件
public void ds(){
try {
FileOutputStream fos = openFileOutput("file_out.txt",
Context.MODE_PRIVATE);
String inputFileContext = "堆放垃圾思考";
fos.write(inputFileContext.getBytes());
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}