JAVA 프로그램의 데이터를 .db 파일에 저장하려고하는데 작동하지 않습니다. 다음과 같은 메시지 오류가 나타납니다.db 파일에 데이터 저장 - java.io.File
"java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source) at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source) at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at server.server.main(server.java:27) Running
"
내 프로그램은 자바 RMI와 함께 작동하는 클라이언트 - 서버 모델입니다. 2 클라이언트, 2 인터페이스 및 다음 서버 클래스 및 모든 메서드를 사용하여 구현 클래스를 포함하여 여러 클래스가 있습니다. 서버 클래스에서
public void save() {
ObjectOutputStream out;
try {
out = new ObjectOutputStream(new FileOutputStream(new java.io.File("C:/Users/Myself/Desktop/Hospital.db")));
out.writeObject(this);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
:
try {
ObjectInputStream in;
try {
in = new ObjectInputStream(new FileInputStream(new java.io.File("C:/Users/Myself/Desktop/Hospital.db")));
read = (implementation)in.readObject();
in.close();
System.out.println(read);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
read = new implementation();
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
read = new implementation();
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
read = new implementation();
e.printStackTrace();
}
이 방법은 다음 두 클라이언트에서 사용되는 "저장"을 다음과 같이
"저장"방법은 구현 클래스입니다.
까지 내가 볼 수있는 _reading_ 파일이 아닌 _writing_ – AlexR
클라이언트가 파일 쓰기를 완료하기 전에 서버가 파일을 읽는 중일 수 있습니다. –