Jak zapisać dane LinkedList w pliku?

0

Witajcie :)

W jaki sposób zapisać dane z LinkedList do pliku??

public class Address {
    private String name;
    private String city;
    
    Address(String n, String c)
    {
        name = n;
        city = c;

    }

    public String toString()
    {
        return name + "\n" + city + "\n";
    }
}
import java.io.*;
import java.util.*;




public class Linq {

    public static void main(String[] args) throws IOException {
        LinkedList<Address> pb = new LinkedList<>();
        pb.add(new Address("Jan Kowalski", "Warszawa"));
    
        
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("C:/Data.txt")));
        out.writeUTF("");
        out.close();
        
        DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("C:/Data.txt")));
        System.out.println(in.readUTF());
        in.close();
    }
}

0
class Address implements Serializable {

A potem zapisuj zwykłym http://docs.oracle.com/javase/7/docs/api/java/io/ObjectOutputStream.html

1 użytkowników online, w tym zalogowanych: 0, gości: 1