爲什麼它說沒有找到拆分方法?我想將一行分成幾部分。但是有錯誤。爲什麼 ?使用逗號從txt和拆分字符串中讀取文件
try {
Scanner a = new Scanner (new FileInputStream ("product.txt"));
while (a.hasNext()){
System.out.println(a.nextLine()); //this works correctly, all the lines are displayed
String[] temp = a.split(",");
}
a.close();
}catch (FileNotFoundException e){
System.out.println("File not found");
}
你爲什麼會認爲有一個'split'方法在'Scanner'實例上? [文檔]中沒有提及(http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#method_summary)。 –