multiple save options
Hi. I came up with a simple text file saving kind of a logic. But I want to enable it to let multiple saves such that each time it is saved, the information in the previous file remains intact. Can someone help me to modify the program? Thanks alot !
import java.io.*;
public class save {
String a;
String b;
int c;
int d;
int e;
int f;
int g;
int h;
public save(String a, int b) throws IOException {
this.a = a;
this.b = b;
File outputFile = new File("game1.txt");
FileOutputStream out = new FileOutputStream(outputFile);
PrintStream fileOutput = new PrintStream(out);
fileOutput.println(a + ";" + Integer.toString(b) + ";");
out.close();
}
}
oops sorry. a little mistake here..
import java.io.*;
public class save {
String a;
int b;
public save(String a, int b) throws IOException {
this.a = a;
this.b = b;
File outputFile = new File("game1.txt");
FileOutputStream out = new FileOutputStream(outputFile);
PrintStream fileOutput = new PrintStream(out);
fileOutput.println(a + ";" + Integer.toString(b) + ";");
out.close();
}
}
huh? try this:
import java.io.*;
public class save {
String a;
int b;
private static counter = 0;
public save(String a, int b) throws IOException {
this.a = a;
this.b = b;
counter++;
File outputFile = new File("game" + counter + ".txt");
FileOutputStream out = new FileOutputStream(outputFile);
PrintStream fileOutput = new PrintStream(out);
fileOutput.println(a + ";" + Integer.toString(b) + ";");
out.close();
}
}