Scrivere su un file

Icona iDevice La classe testScritturaFile
import java.io.*;

class Punto implements Serializable{
// gli attributi ricevono un valore casuale intero minore di 10
long x = Math.round(Math.random()* 10.0);
long y = Math.round(Math.random()* 10.0);
}
public class testScritturaFile {

public static void main(String[] args) {
try{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("c:\\punti.dat"));

long n = Math.round(Math.random()* 10.0);

long i = 0;
while (i < n){
// creo un oggetto
Punto p = new Punto();
// lo scrivo sul file
out.writeObject(p);
// stampo le coordinate dell'oggetto
System.out.println(p.x + " " + p.y);
i++;
}



}catch(IOException e){
System.out.println("errors");
}

}
}