资源简介
Java图书馆借书还书系统,上课时做的一个作业,能读写TXT文件,实现书籍和用户信息的修改和保存,控制台程序,能实现借书、还书、查询用户和书籍信息功能,内附TXT文件保存格式说明
代码片段和文件信息
import java.io.*;
import java.util.*;
public class BookSystem {
public static void main(String[] args){
System.out.println(“请输入书籍信息源文件的地址:“);
String bookAddress = BookSystem.scan.next();
BookSystem.readBookTxt(bookAddress);
System.out.println(“请输入用户信息源文件的地址 :“);
String userAddress = BookSystem.scan.next();
BookSystem.readUserTxt(userAddress);
BookSystem.choose();
BookSystem.writeBookTxt(bookAddress);
BookSystem.writeUserTxt(userAddress);
}
public static void readUserTxt(String userAddress){
String sourceAddress = userAddress;
try{
FileReader fr = new FileReader(sourceAddress);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
User now = BookSystem.firstUser;
while (line != null) {
int index = line.indexOf(“ “);
now.setId(Integer.parseInt(line.substring(0index)));
line = line.substring(index+2);
index = line.indexOf(“ “);
now.setName(line.substring(0index));
line = line.substring(index+2);
index = line.indexOf(“ “);
now.setGender(line.substring(0index));
line = line.substring(index+2);
index = line.indexOf(“ “);
now.setLendNumber(Integer.parseInt(line.substring(0index)));
line = line.substring(index+2);
index = line.indexOf(“ “);
if(index == -1){
now.setMaxNumber(Integer.parseInt(line));
}
else{
now.setMaxNumber(Integer.parseInt(line.substring(0index)));
Book nowBook = now.myBook;
while (index != -1){
line = line.substring(index+2);
index = line.indexOf(“ “);
String bookID = line.substring(0index);
line = line.substring(index+2);
index = line.indexOf(“ “);
String bookName = line.substring(0index);
line = line.substring(index+2);
index = line.indexOf(“ “);
if(index == -1){
int bookNumber = Integer.parseInt(line);
nowBook.nextBook = new Book(bookIDbookNamebookNumber);
nowBook = nowBook.nextBook;
}
else{
int bookNumber = Integer.parseInt(line.substring(0index));
nowBook.nextBook = new Book(bookIDbookNamebookNumber);
nowBook = nowBook.nextBook;
}
}
}
line = br.readLine();
if(line != null){
now.nextUser = new User();
now = now.nextUser;
}
}
br.close();
fr.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
public static void readBookTxt(String bookAddress){
String sourceAddress = bookAddress;
try{
FileReader fr = new FileReader(sourceAddress);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
AllBook now = BookSystem.allBook;
while (line != null) {
int index = line.indexOf(“ “);
now.setBookId(line.substring(0index));
line = line.substring(index+2);
index = line.indexOf(“ “);
now.setName(line.substring(0index));
line = line.sub
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-07-02 15:42 借书还书系统\
文件 118 2012-05-15 22:13 借书还书系统\A.txt
文件 118 2012-05-16 20:46 借书还书系统\B.txt
文件 14917 2012-05-16 22:14 借书还书系统\BookSystem.java
文件 325 2012-07-02 15:42 借书还书系统\说明.txt
- 上一篇:实现了LRU算法的缓存
- 下一篇:安卓版仓库管理系统
相关资源
- 安卓版仓库管理系统
- 基于客户端通信的DES加密的java实现
- Java写的西洋跳棋人机对战
- 基于SpringMVC的JAVA论坛(J2EE BBS 毕业设
- JAVA联机版飞机大战(毕业设计 黄跃然
- 公交查询系统源码(JAVA)
- Java程序框架--多线程异步处理多任务
- 购物网 java源码
- 2048java源码
- java实现MODBUS通讯
- java web实验报告
- 一个模拟windows时钟日历的程序纯Jav
- 人工智能 动物产生式系统 java
- TCP实现的文件上传功能java
- spring 定时器完整 demo
- java进程调度算法
- Java人员信息管理系统
- 局域网传送文件java实现Client端
- java通过jacob调用ocx.rar
- SQLServer数据库课程设计图书馆管理系
- JAVAEE课堂笔记
- 磁盘调度算法 操作系统作业 java模拟
- java gps信号接收与解析
- java读取图片文件流
- javadbf.jar修正数据和表头的乱码问题
- 客户登陆系统 客户在线登陆系统
- Java实现的单态登陆
- java编程实现vox转wav
- java-多线程器支持断点续传、线程加减
- 3D坦克java
评论
共有 条评论