
간단한 일기장을 구현중인 학생입니다. 코드를 참고해서 개발중이긴한데
저 부분에 대한 설명이 없어 질문드려요,,
작성하고 목록으로 돌아오면 저렇게 숫자로 표현되어있어요
System.currentTimeMillis() 이 부분이 문제인거같기도 하고
리스트에 초/분/시간 혹은, 보기쉽게 표현하고 싶은데 어떻게 수정해야할까요
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work);
content = findViewById(R.id.edit);
content.setBackgroundColor(Color.argb(100,213,232,249));
Bundle params = getIntent().getExtras();
fName = params.getString("fName");
if(fName.equals("new")) {
fName = System.currentTimeMillis()+".txt";
Toast.makeText(this,"새로운 일기를 입력하세요.",Toast.LENGTH_SHORT).show();
} else {
content.setText(readFile(this));
Toast.makeText(this,"저장된 일기를 표시합니다.",Toast.LENGTH_SHORT).show();
}
listBtn = findViewById(R.id.listBtn);
listBtn.setOnClickListener(this);
saveBtn = findViewById(R.id.saveBtn);
saveBtn.setOnClickListener(this);
delBtn = findViewById(R.id.delBtn);
delBtn.setOnClickListener(this);
}
public String readFile(Context c) {
FileInputStream in = null;
ByteArrayOutputStream out = null;
int len = 0;
byte[] bStr = new byte[1024];
try{
in = c.openFileInput(fName);
out = new ByteArrayOutputStream();
while ((len = in.read(bStr)) != -1)
out.write(bStr,0,len);
out.close();
in.close();
} catch (Exception e) {
try{
if (out != null) out.close();
if(in != null) in.close();
}catch (Exception e2) {
e2.printStackTrace();
}
}
return out.toString();
}
public void saveFile(Context c, String cStr) {
FileOutputStream out = null;
byte[] bStr = cStr.getBytes();
try{
out = c.openFileOutput(fName,Context.MODE_PRIVATE);
out.write(bStr,0,bStr.length);
out.close();
} catch (Exception e) {
try{
if(out != null) out.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}