读书人

Exception in thread quot;mainquot; java.lan

发布时间: 2011-11-10 21:42:48 作者: rapoo

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

读书人网 >Eclipse开发

热点推荐