1
내 프로그램은 기본적으로 일일 플래너입니다.자바에서 ObjectInputStream을 사용하여 파일에서 문자열 배열 검색?
일정은 ObjectOutputStream에 의해 월 및 연도별로 파일에 저장됩니다. 확인
일정은 하루 단위로 배열됩니다. 확인
예약은 ObjectInputStream에 의해 검색됩니다. 이것은 내가 문제가있는 곳입니다.
public class Calendar {
public String date;
public String[] schedule = new String[31];
Calendar(){
}
public String retrieve(int month, int day, int year) {
date = Integer.toString(month) + "-"+ Integer.toString(year) + ".txt";
try {
ObjectInputStream input = new ObjectInputStream(new
FileInputStream(date));
input.readObject();
schedule = input;
//This is where I have the error obviously schedule is a string array and
//input is an ObjectInputStream so this wont work
input.close();
return schedule[day-1];
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "File not found";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "IOException";
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "ClassNotFound";
}
}
public void save(int month, int day, int year, JTextArea entry) {
date = Integer.toString(month) + "-"+ Integer.toString(year) + ".txt";
schedule[day-1]= entry.getText();
try {
ObjectOutputStream output = new ObjectOutputStream(new
FileOutputStream(date));
output.writeObject(schedule);
output.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
일정
확인entry.setText(calendar.retrieve(month,day,year));