我想要一个System类来读取已经写在文本文件中的书籍。
import java.io.BufferedReader;
import java.io.FileReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class System
{
private String FILENAME = "books.txt";
private static final int MAX_BOOKS = 10;
public void readBooks()
{
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(FILENAME));
String line = null;
int count=0;
while ((line = br.readLine()) != null && count < MAX_BOOKS) {
String[] values = line.split(",");
String ISBN = values[0];
String author = values[1];
String title = values[2];
String subject = values[3];
String inputDate = "04/04/2015";
SimpleDateFormat formatter = new SimpleDateFormat("d/M/yyyy");
Date date = null;
try {
date = formatter.parse(values[4]);
}
catch (ParseException exc)
{
System.out.println("A date format error occurred"); //***
}
Transaction bok = new Book(ISBN,author,title,subject,date);
books[count] = bok;
count++;
}
br.close();
numberOfBooks = count;
System.out.println("Books read from file successfully");
updateBalance();
}
catch (Exception ex) {
System.out.println("A file error occurred");
}
}
}
标题中的错误是指我突出显示的System.out.println。为什么会出现此错误以及如何解决?提前谢谢!
答案 0 :(得分:3)
将您的课程重命名为System
以外的其他内容,以便可以使用Java自己的java.lang.System