我得到一個StringIndexOutOfBoundsException
的線路閱讀(line.charAt(0) == 'I')
,它說String index is out of range at 0
。當試圖評估文件輸入時StringIndexOutOfBoundsException?
我不確定這裏要做什麼。
QueueLinkedList<Customer> eventqueue = new QueueLinkedList<Customer>();
QueueLinkedList<Customer> customerqueue = new QueueLinkedList<Customer>();
int numberserved = 0, totalidletime = 0, longestbreak = 0, idletime = 0, linelength = 0, longestline = 0;
try {
File file = new File("customersfile.txt");
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
//empty lines
while ((line = reader.readLine()) != "") {
//first line of file
while ((line = reader.readLine()) != "300") {
Customer newcust = new Customer();
if (line.charAt(0) == 'I') {
newcust.id = line.charAt(11);
}
else {
newcust.arrtime = line.substring(14);
newcust.setarrtimesecs(newcust.arrtime);
newcust.setleavingtime(newcust.arrtime);
}
eventqueue.enqueue(newcust);
}
}
}
}catch (IOException e) {
e.printStackTrace();
}
爲什麼使用reader.readLine())!= null爲什麼不只是hasNextLine(),我認爲你的方式會保持真實的空行 –