个人觉得有意义的部分
“记住密码”功能讲展示tip变成一个独立的工具类使用TreeTable,其归档作用用在这里十分合适学到的东西
RandomAcessFile 就是C的文件指针,超好用,可以同时读写还可以跳,除了无法实现删除,定位修改什么的都十分容易JavaFx的定位系统Point2DJavaFX的控件TreeTable,DatePicker部分展示
头像显示不正常,因为资源的路径没办法正确编译进去数据存储部分 数据文件并未加密signedAdmin 存放注册管理员相关 signedUser 存放注册用户相关 Books 存放所有书籍数据存储部分代码
用户存书 User.saveBooks 查看整个文件用户取书和验证是一起进行的,为了减少读写文件的次数,所以这里不贴出,感兴趣可以看源文件Store.isSigned public void saveBooks(){ File file = new File(fileName); try { PrintWriter out = new PrintWriter(fileName+".bak"); Scanner in = new Scanner(file); while(in.hasNextLine()){ String line = in.nextLine(); ArrayList<String> each = new ArrayList<>(); each.addAll(Arrays.asList(line.split(" "))); if (each.get(0).equals(name)){ if (each.indexOf("<Books>")==-1){ out.print(line+" "); }else { for (int i = 0; i < each.indexOf("<Books>"); i++) { out.print(each.get(i) + " "); } } out.print("<Books> "); hadBooks.forEach(i -> out.print(i+" ")); out.println("</Books>"); }else out.println(line); } in.close(); out.close(); Files.delete(Paths.get(fileName)); new File(fileName+".bak").renameTo(file); } catch (IOException e) { System.out.println("文件写入出错"); e.printStackTrace(); } } 书店存书Store.saveBooks查看源文件 static void saveBooks() { try { PrintWriter in = new PrintWriter("Books"); //in.append(each); Attention:FileWriter.append不是追加内容,是流操作 Controller.showAll.forEach(in::println); in.close(); } catch (IOException e) { System.out.println("文件写入出错"); e.printStackTrace(); } } 书店取书(读出书店所有的存书)查看源文件 static ArrayList<Book> importBooks() { addedBooks = new ArrayList<>(); ArrayList<Book> allBooks = new ArrayList<>(); if(!Paths.get("Books").toFile().exists()) { return allBooks; } try { Files.readAllLines(Paths.get("Books")).stream().map(line -> { String[] each = line.split(","); return new Book(each[0], each[1], each[2], parseInt(each[3])); }).forEach(allBooks::add); } catch (IOException e) { e.printStackTrace(); } return allBooks; }Git链接:https://github.com/dongmingchao/LibrarySystem 最好clone下来感受,或者在github上有jar包,细节比较多
转载于:https://www.cnblogs.com/DedSec/p/8012638.html
相关资源:JAVA上百实例源码以及开源项目