0
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);
    } 

}

And here is the output

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)
seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • Dont use `!=` for comparing String you have to use `.equals()` instead – seenukarthi Mar 06 '16 at 03:53
  • As others have indicated, don't use the not equal operand to compare strings. In addition check what the value you have in the next line. You might have a non integer string. Or you might have a big value which could not be represented by an integer. – Ruchira Randana Mar 06 '16 at 04:10

0 Answers0