@Override
public void onClick(View v) {
Button button = (Button) v;
String filename = filenameText.getText().toString();
switch (button.getId()) {
case R.id.save:
String sendResult = "保存成功!";
String content = contentText.getText().toString();
OutputStream outputStream;
try {
outputStream = FileSaveReadActivity.this.openFileOutput(filename, MODE_APPEND);
FileService.save(outputStream, content);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sendResult = "保存失败";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
sendResult = "保存失败";
}
Toast.makeText(FileSaveReadActivity.this, sendResult, Toast.LENGTH_LONG).show();
break;
case R.id.read:
try {
InputStream inputStream = FileSaveReadActivity.this.openFileInput(filename);
String contentShow = FileService.read(inputStream);
TextView contentShowLabel = (TextView) FileSaveReadActivity.this.findViewById(R.id.readContent);
contentShowLabel.setText(contentShow);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(FileSaveReadActivity.this, "读取失败", Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(FileSaveReadActivity.this, "读取失败", Toast.LENGTH_LONG).show();
}
break;
}
}
};
}