UrbanTwitch
09-27-2009, 09:35 PM
Let's say I want to make an RPG in Java.. (console application) and I want to save the user's input of Name, level, exp, gold,... what would be the best way I can save that data and load it for use in Strings and such?
Right, at the moment, I am using Textfiles... but if I want to append a textfile like... save the new number for gold... I'd have to write on ALLL lines like
// more code...
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
try { out = new FileOutputStream("stats.txt");
p = new PrintStream( out );
p.println(name);
p.println("500"); // gold
p.println("1"); // level
p.println("1"); // exp
p.println("1"); // room
p.println("100"); // current hp
p.println("100"); // max hp
p.close();
}catch (IOException ioe)
{
System.out.println("An unexpected error occured.");
}//end catch errors
// more code...
See what I mean? Is there a way to append a line of text to a single line of text like... append "Boo?" to line number 3 in stats.txt or maybe replace line 2 with "1242"?
Right, at the moment, I am using Textfiles... but if I want to append a textfile like... save the new number for gold... I'd have to write on ALLL lines like
// more code...
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
try { out = new FileOutputStream("stats.txt");
p = new PrintStream( out );
p.println(name);
p.println("500"); // gold
p.println("1"); // level
p.println("1"); // exp
p.println("1"); // room
p.println("100"); // current hp
p.println("100"); // max hp
p.close();
}catch (IOException ioe)
{
System.out.println("An unexpected error occured.");
}//end catch errors
// more code...
See what I mean? Is there a way to append a line of text to a single line of text like... append "Boo?" to line number 3 in stats.txt or maybe replace line 2 with "1242"?