This is my first stack overflow question, hope you can help me. I did a bit of work on the Internet, but I continue to find tutorials or answers that talk about reading text files using BufferedReader or reading bytes from files on the Internet. Ideally, I would like to have a file on my server called "http://ascistudent.com/scores.data" that stores all Score objects made by players from the game I made.
The game is a simple “drop game” in which you try to get 3 of the same blocks that concern, increase the score. When the time runs out, points are loaded from the file, their score is added to the correct position of the objects in the list of objects. After that, the ratings are again saved in one file.
I am currently getting an exception, java.io.EOFException on the highlighted line:
URL url = new URL("http://ascistudent.com/scores.data");
InputStream is = url.openStream();
Score s;
ObjectInputStream load;
load = new ObjectInputStream(is);
while ((s = (Score)load.readObject()) != null){
scores.add(s);
}
load.close();
I suspect this is because the file is empty. But then, when I catch this exception and say that it is still written to the file (after changing the list of results) with the following code, nothing appears (the exception continues to occur.)
URL url = new URL("http://ascistudent.com/scores.data");
URLConnection ucon = url.openConnection();
ucon.setDoInput(true);
ucon.setDoOutput(true);
os = ucon.getOutputStream();
ObjectOutputStream save = new ObjectOutputStream(os);
for(Score s:scores){
save.writeObject(s);
}
save.close();
What am I doing wrong? Can someone point me in the right direction?
Thanks a lot, Luke
lukey source
share