1. Project requirements
(1) Reader information management: including the functions of adding reader information and querying and modifying reader information. After logging in successfully, users can browse the information of all readers and retrieve the information of specific readers; At the same time, you can maintain the reader information, including adding, deleting and modifying. Specific information includes the type of Reader (the type of reader determines the maximum number of books he can borrow and the maximum number of days to return), the reader's name, date of birth, gender, telephone, Department, registration date, etc. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(2) Library Information Management: including the functions of adding book information and querying and modifying book information. After logging in successfully, users can browse all book information and retrieve the information of specific books; You can also maintain book information. Including adding books, deleting books and modifying book information. Specific information includes: Book ISBN, book name, author, publisher, publication date, printing times, unit price, book category, etc. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(3) Book borrowing management: including book borrowing and book return functions. Book borrowing function: first input the reader's number, then input the information of the book to be borrowed, and record the current time of the system, that is, the borrowing time; Book return function: input the reader's number, select the borrowed books under its name, judge whether the current date, that is, the difference between the return date and the borrowing date exceeds the specified period, and calculate the penalty, so as to return the books. Specific information includes: borrowing date, return date and penalty. To calculate the penalty, it is necessary to know the reader type of the reader, and judge the number of books that can be borrowed and the number of books that can be borrowed according to the type. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(4) Basic information maintenance: including book category setting, reader category setting and fine setting. Book category settings: you can add, delete, modify and query book categories; Reader category settings can add, delete, modify and query the category of readers; Penalty setting: you can specify the penalty standard for one day overdue. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
(5) User management: including password modification, user addition and deletion. Change password means that the current user changes his password; User addition and deletion are the maintenance of user information when adding and removing system users. (relevant stored data can be directly stored in the file through I/O stream, and can also be read directly in the file)
2. Summary
In this project, I use character streams BufferedReader and BufferedWriter to access files from I\O streams,
BufferedWriter has a line feed method newLine()
BufferedWriter bwN = new BufferedWriter(new FileWriter("H:\\Library\\Books/title.txt", true)); bwN.write(bookName); bwN.newLine(); bwN.flush(); bwN.close();
BufferedReader has a line reading method readLine()
BufferedReader brbn = new BufferedReader(new FileReader("H:\\Library\\Books/title.txt")); String bn = null; while ((bn = brbn.readLine()) != null) { arbn.add(bn); } brbn.close();
During the operation, I write the data to be stored row by row each time. When I use it, I put it into the array in the reading of row by row.
Here, in order to facilitate the modification of attributes, I built multiple files according to the attributes, and write and read correspond to each other one by one.
Because every time you want to use data, you have to read it and then save it. The consequence is that there is too much code and you write yourself dizzy.
Later, I thought about the split() method to divide the content with spaces (because I wrote most of it myself, I'm too lazy to change it again)
public void test1() throws IOException { FileReader fr = new FileReader("H:\\STU/aa.txt"); int data; String str = null; char[] cbuf = new char[1024]; while ((data=fr.read(cbuf,0,1024))!=-1){ str = new String(cbuf,0,1024); } fr.close(); String[] str1=str.split(" "); for (int i =0;i<=str1.length-1;i++){ System.out.print(str1[i]); } }
When saving, separate each part with a space, save it in the same line, wrap it and write it again,
When reading, read by line, divide the contents with spaces and store them in different arrays.
3. Tips gained from the project
Regular limit options
String pChoose2 = "[1|2]"; System.out.println("1.Continue adding 2.return"); String strChoose; strChoose = scanner.next(); while (!strChoose.matches(pChoose2)) { System.out.println("Please enter the correct option"); strChoose = scanner.next(); } int choose = Integer.valueOf(strChoose);