当前位置: 代码迷 >> Eclipse >> Exception in thread "main" java.lang.NumberFormatException:
  详细解决方案

Exception in thread "main" java.lang.NumberFormatException:

热度:433   发布时间:2016-04-23 18:59:05.0
从文本文件中读出点的坐标
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 + ">");
  相关解决方案