Im developing a large scale GUI program, where I have alot of project data that needs to be stored locally
on command.
Currently, I'm saving all the global data structures in a save class (project), and then serializing them to a local harddisk file:
public void saveChanges() {
ArrayList<Student> studentList = new ArrayList<>();
ArrayList<String> coursesList = new ArrayList<>();
ArrayList<Requirement> reqList = new ArrayList<>();
ArrayList<Risk> riskList = new ArrayList<>();
for (int x = 0; x < dlm.getSize(); x++) {
studentList.add(dlm.elementAt(x));
}
for (int x = 0; x < dlm2.getSize(); x++) {
coursesList.add(dlm2.elementAt(x));
}
for (int x = 0; x < dlm3.getSize(); x++) {
reqList.add(dlm3.elementAt(x));
}
for (int x = 0; x < riskTable.getRowCount(); x++) {
riskList.add((Risk) riskMap.get(dtm1.getValueAt(x, 0)));
}
project.setStudentAL(studentList);
project.setCoursesAL(coursesList);
project.setReqAL(reqList);
project.setRiskAL(riskList);
project.setLastUpdated(new Date().toString());
}
Now i'm serializing this to a local file:
public void saveProject(boolean defaultPath, String path) {
saveChanges();
FileOutputStream outFile;
try {
if (defaultPath) {
outFile = new FileOutputStream(directory + project.getProjectName() + ".proj");
} else {
outFile = new FileOutputStream(path + ".proj");
}
ObjectOutputStream outObject = new ObjectOutputStream(outFile);
outObject.writeObject(project);
outObject.close();
} catch (IOException e) {
System.out.println("Failed to save project");
e.printStackTrace();
}
}
My question is this: Is there a default; or better way to save files on your local harddrive? I dont want to use XML or any DB.
- Thanks in advance