These are just simple methods you can have to save/load text files
Code:
public void makeTextFile(String fileName) {
File f = new File("./data/cat-lives/" + fileName + ".txt");
if (f.exists()) {
System.out.println("File already exists");
return;
}
saveInformation(fileName);
}
public void saveInformation(String fileName) {
String filePath = "./data/cat-lives/" + fileName + ".txt";
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(filePath));
bw.write("Cat-lives = ", 0, 12);
bw.write(Integer.toString(Npc.getDefinition().catLives), 0, Integer.toString(Npc.getDefinition().catLives).length());
bw.flush();
}
catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
}
catch (IOException ioe2) {
}
}
}
}
public void loadInformation(String fileName) {
Properties p = new Properties();
File folder = new File("./data/cat-lives");
File[] files = folder.listFiles();
boolean ls = false;
for (int i = 0; i < files.length; i++) {
String currentFile = files[i].toString();
try {
if (files[i] != null && files[i].exists()) {
p.load(new FileInputStream(currentFile));
Npc.getDefinition().catLives = Integer.parseInt(p.getProperty("Cat-Lives"));
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}