文字档案
Book
VAM-001
Dracula
Stoker, B
14
true
null
Book
WIW-001
The Wind In the Willows
Grahame, K.
14
true
null
Book
WAP-001
War and Peace
Tolstoy, L.
14
true
null
Book
MIL-001
The Girl with the Dragon Tattoo
Larsen, S.
14
true
null
Book
CRU-001
The Crucible
Miller, A.
14
true
null
Book
LTR-001
The Fellowship of the Rings
Tolkien, J. R. R.
14
true
null
Book
WOT-001
The Eye of The World
Jordan, R.
14
true
null
Textbook
JAV-001
Introduction to Java Programming
Liang, D.
2
true
null
COSC1073 COSC1284 COSC2531 COSC1295
Textbook
DBC-001
Fundamentals of Database Systems
Elmasri, R. & Navathe, S.
2
true
null
ISYS1057
Textbook
WST-001
HTTP: The Definitive Guide
Gourley, D. & Totty, B.
2
true
null
COSC1285
Textbook
AIN-001
Artificial Intelligence - A Modern Approach.
Russell, S. & Norvig, P.
2
true
null
COSC1127
Textbook
ITP-001
Introduction to Computing and Programming in Python.
Guzdial, M. & Ericson, B.
2
true
null
COSC1519
Book
VAM-002
Interview with a Vampire
Rice, A.
14
true
null
Book
MIL-002
The Girl Who Played with Fire
Larsen, S.
14
true
null
Book
WIZ-001
A Wizard of Earthsea
Le-Guin, U. K.
14
true
null
Book
WIZ-002
Harry Potter and the Deathly Hallows
Larsen, S.
14
true
null
Book
BOU-001
The Bourne Identity
Ludlum, R.
14
true
null
Book
DIC-001
A Tale of Two Cities
Dickens, C.
14
true
null
Book
TGG-001
The Great Gatsby
Fitzgerald, F. S.
14
true
null
Book
MOD-001
Moby Dick
Melville, H.
14
true
null
Java代码
BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append("\n");
line = br.readLine();
}
String[] books = sb.toString().split("\n");
System.out.println(Arrays.toString(books));
} finally {
br.close();
}
我已成功读取该文件,但我不知道如何解析数据。我必须将书籍存放在一个班级,将教科书存放在不同的班级。每个条目都有6个字段:
此文本文件中的分隔符是换行符(\n
)。请帮我。提前谢谢!
答案 0 :(得分:1)
创建Book类为其添加书籍ID,标题,作者,贷款天数,可用性和成员代码字段。然后从Book驱动TextBook类,并将它添加到普通书籍没有的第七个字段(COSC1127)。当您在读取“Book”行时读取行,当您创建一个书籍对象并填充它时,当您阅读“TextBook”时创建一个TextBook并填写它。而不是保持一个String数组为Book和TextBook创建两个列表,并将您的对象添加到列表中。