我在阅读表单文件时遇到数字格式异常

时间:2016-03-06 03:51:06

标签: java

public class List {

    public static void main(String[] args) {

        //java.util.List<String> slist= new ArrayList<String>();

        try {
                FileInputStream f = new FileInputStream("V:/files/student.txt");
                InputStreamReader reader = new InputStreamReader(f);
                BufferedReader br = new BufferedReader (reader);
                String line = null;
                int id;
                String sname,subname,date;
                while (((line = br.readLine().trim()) != "/0")) {
                String[] parts = line.split(",\\s*");
                id=Integer.parseInt(parts[0]);
                sname=parts[1];
                subname=parts[2];
                date=parts[3];
                System.out.print(id+" "+sname+" "+subname+" "+date);
                System.out.println();
                //slist.add(sname);
                /*System.out.print(line);
                System.out.println();
                slist.add(line);*/
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //System.out.println(slist);
    } 

}

这是输出

101 Snehal Patil Physics 17:05:2014
106 Rahul Rautwar Maths 20:05:2014
104 Akshata Guru Chemistry 17:05:2014
109 Swapnil Patil Chemistry 22:05:2014
106 Rahul Rautwar Physics 21:05:2014
101 Snehal Patil Chemistry 27:05:2014
104 Akshata Guru Maths 08:05:2014
109 Swapnil Patil Maths 25:05:2014
109 Swapnil Patil Physics 14:05:2014
104 Akshata Guru Physics 13:05:2014
101 Snehal Patil Maths 08:05:2014
106 Rahul Rautwar Chemistry 27:05:2014
Exception in thread "main" java.lang.NumberFormatException: For input string: "/0"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at com.hcl.fileio.List.main(List.java:25)

0 个答案:

没有答案