So I'm trying my hand at some basic file i/o following a few online tutorials and such. I think I have the right idea but there is a multitude of ways to accomplish this, and varying examples are starting to make my head spin. My code definitely could use some help...
Ironically, the reason I cannot compile currently actually due to newLine() not being recognizable. I ran into this problem using \n in a drawString before, but this is not as easy to work around.
Here is my code for the I/O. If it would be more helpful to post the entire class I will do so, but it is lengthy.
public static int[] loadScores() throws IOException
{
//load preiviously saved scores from file
BufferedReader inputStream = null;
int scoreArray[] = new int[5];
inputStream = new BufferedReader(new FileReader("highscores.txt"));
int num = 0; //line count
String t = "";
int start = Integer.parseInt(inputStream.readLine()); //first number in file
while((t = inputStream.readLine()) != null) // only if there is something to read
{
scoreArray[num] = Integer.parseInt(t);
num++;
}
inputStream.close();
return scoreArray;
}//save new array of highscores to file
FileWriter outputStream = null;
outputStream = new FileWriter("highscores.txt", false);
for (int k=0; k < allArray.length; k++)
{
outputStream.write(allArray[k]);
outputStream.newLine();
}
outputStream.close();
}

