1
任何人都可能能夠告訴我爲什麼此代碼不打印輸出?我沒有收到任何錯誤,但它只是不打印。它是從.txt文件讀取的(下面的代碼在下面)。從文件中讀取不是打印到輸出
代碼:於明年其他
public class ReadFromFile {
public static void main(String[] args) throws FileNotFoundException {
File file = new File("CarInfo.txt");
try (Scanner sc = new Scanner(file)) {
while (sc.hasNext()) {
String carTab = sc.next();
// Looking for tag 'Station:'
if (!carTab.equals("Car:")) continue;
if (!sc.hasNext()) {
break;
}
Car = sc.next();
if (!sc.hasNextInt()) {
continue;
}
int x = sc.nextInt();
if (!sc.hasNextInt()) {
continue;
}
int y = sc.nextInt();
System.out.println(car + " " + x + " " + y);
}
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
}
}
設置一個斷點後,它不會消耗任何東西,通過您的代碼步。這比讓我們猜測什麼是錯誤要容易得多。 – f1sh
我測試了您的代碼沒關係 – Abdelhak
@Abdelhak是否爲您打印? – BlaBla