保存项目数据.你会怎么做?

Dan*_*Mac 5 java user-interface swing arraylist save

我开发了一个大规模的GUI程序,我有很多需要存储locally在命令中的项目数据.

目前,我将所有全局数据结构保存在保存类(项目)中,然后将它们序列化为本地硬盘文件:

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());

}
Run Code Online (Sandbox Code Playgroud)

现在我将其序列化为本地文件:

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:是否存在违约; 或者更好的方法来保存本地硬盘上的文件?我不想使用XML或任何数据库.

  • 提前致谢