詮釋我有這樣的代碼,但是當我嘗試運行它,我得到這個錯誤 Exception in thread "main" java.lang.NumberFormatException: For input string: "1"
每一道線條都是包含了一些名稱的電子郵件和日期,以便在每一行的第一個字符是數字。該tomb[0]
僅僅是一個數字串用的BufferedReader
List<Szemely> lista = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(this.szemelyekcsv))) {
String line;
while ((line = br.readLine()) != null) {
String[] tomb;
tomb = line.split(";");
int sor = Integer.parseInt(tomb [0]);
DateTimeFormatter sima = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate szul = LocalDate.parse(tomb[3], sima);
lista.add(new Szemely(sor, tomb[1], tomb[2], szul));
}
} catch (FileNotFoundException ex) {
System.out.println("Nem tudom megnyitni a 'be.txt' fájlt.");
} catch (IOException ex) {
System.out.println("Hiba a 'be.txt' fájl olvasása közben.");
}
當程序到達此行
int sor = Integer.parseInt(tomb [0]);
全自動跳回
try (BufferedReader br = new BufferedReader(new FileReader(this.szemelyekcsv)))
和錯誤... 感謝所有幫助。
什麼是墓[0] .. .try首先打印它... –
哦對不起。每一行都包含一個名字,一個電子郵件和一個日期。所以每一行中的第一個字符就是數字。 –
你能否提供一個[mcve]這很奇怪,因爲這個應該是可解析的,所以這個異常給了String'「1」'。例如,你可能不需要'File',一個'String'應該足夠了,只要在發佈之前重試就可以了。 – AxelH