package chenyang;
import java.util.*;
import java.io.*;
public class Bookset{
private TreeSet bookSet;
public Bookset() throws IOException{
bookSet=new TreeSet(new Bookcomp());
try {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new FileWriter("booklist.txt",true));
System.out.println("请输入书籍记录:");
String str="";
do{
bw.newLine();
System.out.flush();
str=br.readLine();
if(str.length()==0||str.equals("stop")) break;
bw.write(str);
}
while(!str.equals("stop"));
bw.close();
} catch(FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
}
public void output()throws IOException{
try {
BufferedReader in = new BufferedReader(new FileReader( "booklist.txt"));
String str;
StringTokenizer st ;
while ((str = in.readLine()) != null) {
st = new StringTokenizer(str, ",");
while(st.hasMoreTokens()) {
String bookname = st.nextToken();
String writer = st.nextToken();
String number = st.nextToken();
String date = st.nextToken();
String price = st.nextToken();
bookSet.add(new Book(bookname,writer,number,date,price));
}
}
in.close();
} catch(FileNotFoundException e) {
System.out.println("File Not Found");
return;
}
}
public String[][] list() {
String list[][]=new String[ bookSet .size()][5];
Iterator itr=bookSet.iterator();
int i=0;
while (itr.hasNext()){
Book book=(Book)itr.next();
list[i][0]=book.getBookname();
list[i][1]=book.getWriter();
list[i][2]=book.getNumber();
list[i][3]=book.getDate();
list[i][4]=book.getPrice();
i++ ;
}
return list;
}
}
shuji.zip_shuji .com
版权申诉
56 浏览量
2022-09-19
21:49:31
上传
评论
收藏 2KB ZIP 举报
四散
- 粉丝: 52
- 资源: 1万+