我碰上了一个我解决不了的文件读取和保存方面的问题,请大家帮我看一下
代码
public void save__OnClike(View view) {
try {
FileOutputStream out = openFileOutput("xyxdata.txt", MODE_PRIVATE);
String content = TV.getText().toString();
// byte[] bytes = content.getBytes();
out.write(content.getBytes());
out.flush();
out.close();
} catch (IOException e) {
}
}
public void read_text() {
try {
FileInputStream inputStream = this.openFileInput("xyxdata.txt");
byte[] bytes = new byte[1024];
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
while (inputStream.read(bytes) != -1) {
arrayOutputStream.write(bytes, 0, bytes.length);
}
inputStream.close();
arrayOutputStream.close();
String content = new String(arrayOutputStream.toByteArray());
TV.setText(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}