首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

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

2011-11-10 
从文本文件中读出点的坐标public class w {public static void main(String args[]) throws NumberFormatE

从文本文件中读出点的坐标
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 + ">"); 

热点排行