Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cwiczenie31 {
- public static void main(String[] args) {
- try {
- zapiszOsoby();
- odczytajOsoby();
- } catch (IOException ex) {
- ex.printStackTrace();
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- }
- }
- public static void zapiszOsoby() throws IOException {
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("osoby.data"));
- Set<Osoba> osoby = new HashSet<>();
- osoby.add(new Osoba(15, "Jan", 82.5f));
- osoby.add(new Osoba(25, "Monika", 65));
- osoby.add(new Osoba(31, "Krzysztof", 72));
- out.writeObject(osoby);
- }
- public static void odczytajOsoby() throws IOException, ClassNotFoundException {
- ObjectInputStream in = new ObjectInputStream(new FileInputStream("osoby.data"));
- Set<Osoba> osoby = (Set<Osoba>) in.readObject();
- for (Osoba osoba : osoby) {
- System.out.println(osoba.getImie());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement