PHP Code:
public static ArrayList<Person> personenListe = new ArrayList<Person>();
PHP Code:
public static void personendaten_speichern(String pDatei) throws IOException {
ObjectOutputStream outputStream = null;
try {
outputStream = new ObjectOutputStream(new FileOutputStream(pDatei));
for (int i = 0; i < personenListe.size(); i++) {
Person p1 = personenListe.get(i);
outputStream.writeObject(p1);
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
if (outputStream != null) {
outputStream.flush();
outputStream.close();
}
} catch (IOException e) {}
}
}
Laden:
PHP Code:
public static void personendaten_laden(String pDatei) throws IOException {
ObjectInputStream inputStream = null;
try {
inputStream = new ObjectInputStream( new FileInputStream(pDatei));
while(inputStream.readObject() != null) { // Die Schleife
Person p1 = (Person) inputStream.readObject();
personenListe.add(p1);
}
} catch ( IOException e ) { System.err.println( e ); }
catch ( ClassNotFoundException e ) { System.err.println( e );
} finally {
try { inputStream.close();
} catch ( Exception e ) { }
}
}
Meine bitte ist also ob mir jemand sagen kann wie ich das so hin bekomme, dass ich auch aus der Datei laden kann.
PS: Werde morgen mal ausprobieren, danke Saedelaere!






