bSave.setOnClickListener(new View.OnClickListener() {
@Override // 입력한 데이터를 파일에 추가로 저장하기
public void onClick(View v) {
String data = et.getText().toString();
try {
FileOutputStream fos = openFileOutput
("myfile.txt", // 파일명 지정
Context.MODE_PRIVATE);// 저장모드
PrintWriter out = new PrintWriter(fos);
out.println(data);
out.close();
Toast.makeText(getApplicationContext(), "메모가 저장 되었습니다.",0).show();
//et.setText("파일 저장 완료");
} catch (Exception e) {
e.printStackTrace();
}
}
});
bList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 파일의 내용을 읽어서 TextView 에 보여주기
try {
// 파일에서 읽은 데이터를 저장하기 위해서 만든 변수
StringBuffer data = new StringBuffer();
FileInputStream fis = openFileInput("myfile.txt");//파일명
BufferedReader buffer = new BufferedReader
(new InputStreamReader(fis));
String str = buffer.readLine(); // 파일에서 한줄을 읽어옴
while (str != null) {
data.append(str + "\n");
str = buffer.readLine();
}
et.setText(data);
buffer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
이게 mainActivity.java 코딩인데요
여기서는 한 레이아웃에 EditText에 글을 쓰서 저장을 하고 읽기를 누르면 저장한 글을 EditText에 보여주는
코드입니다.
근데 제가 하고싶은건 second.xml을 만들어서 여기에 TextView를 만들어 놓고
EditText에 글을써서 저장하고 읽을때 위에 만든 TextView에 저장된 글을 보여주고 싶은데요
어떻게 해야 할까요? second.java 도 추가해야될까요? 코딩을 어디에 어떻게 해야 할지 모르겠네요
답변 부탁드릴게요