I read a couple tutorials online, including ones here, but I must have gotten something wrong.
import java.io.Serializable;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.IOException;
public class HighScore implements Serializable
{
private Integer highScore;
public HighScore()
{
highScore = 0;
}
public int getHighScore() { return highScore; }
public void setHighScore(int i) { highScore = i; }
public void writeObject() throws IOException
{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("score.out"));
oos.writeObject(highScore);
oos.flush();
oos.close();
}
public Integer readObject() throws IOException, ClassNotFoundException
{
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("score.out"));
return (Integer) ois.readObject();
}
}

New Topic/Question
Reply




MultiQuote








|