public class w {
public static void main(String args[]) throws NumberFormatException,IOException {
BufferedReader br = new BufferedReader(new FileReader("D://1.txt"));
String str = "";
while ((str = br.readLine()) != null && str != "") {
String[] p = str.split(",");
int x = Integer.parseInt(p[0]);
int y = Integer.parseInt(p[1]);
System.out.println("<"+x+","+y+">");
}
}
}
这段程序执行后有错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0,1"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at w.main(w.java:13)
怎么改?
------解决方案--------------------
- Java code
BufferedReader br = new BufferedReader(new FileReader("D://1.txt")); String str = ""; while ((str = br.readLine()) != null && str != "") { String[] p = str.split(","); int x = Integer.parseInt(p[0]); int y = Integer.parseInt(p[1]); System.out.println("<" + x + "," + y + ">");