개체를 문서에 넣으려고합니다. 그 다음에 그들은 읽을 수 있습니다. 문제는 내가 가지고있는 파일을 읽을 수 있다는 것입니다. 폴더에 파일이있는 경우 폴더를 찾은 것입니다 ...레코더/플레이어 개체를 사용하는 방법
나는 objets와 같이 작업하고 있습니다 :
public class Person {
public int Id;
public String Name;
public boolean Show;
public Persona(
int identificator,
String newName,
boolean ShoworNot
){
this.Id = identificator;
this.Name = newName;
this.Show = ShoworNot;
}
Thanks
my code:
public void WriteFile
try {
FileOutputStream file = new FileOutputStream("try.dat");
ObjectOutputStream exit = new ObjectOutputStream(file);
Iterator ite2 = people.iterator();
while(ite2.hasNext()){
Person person2 = (Person)ite2.next();
exit.writeObject(person2);
exit.close();
}
System.out.println("It's works");
}
catch (IOException e){
System.out.println("Problems with the file.");
}
}
}
}
}
public void ReadFile(){
try {
FileInputStream file2 = new FileInputStream("try.dat");
ObjectInputStream entry = new ObjectInputStream(file2);
entry.readObject();
String data = (String)entry.readObject();
entry.close();
System.out.println(data);
}
catch (FileNotFoundException e) {
System.out.println("It can't open the file document");
}
catch (IOException e) {
System.out.println("Problems with the file");
}
catch (Exception e) {
System.out.println("Error reading the file");
}
}
를 호출해야합니다 또한
: 당신이하지
String
Person
을 읽을 수 있어야합니다, 그래서 당신은 객체Person
를 작성 – alaster