3 Replies Latest reply on Aug 21, 2007 2:37 PM by abillconsl

    NumberFormat Exception

    807605
      Hi ,
      I am trying to run the following code which reads a text file's last line (will be of the form "5 Dir(s) 2,617,622,528 bytes free" for example) and using string tokenizer i got the string "2617622528" . But when i try to convert it to integer as i need to perform some calulations on this number i am getting the following exception:
      java.lang.NumberFormatException: For input string: "2617622528"
           at java.lang.NumberFormatException.forInputString(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at FileParse.main(FileParse.java:34)


      Code:
      try
                {
                     int i = 1;
                     int freeSpace;
                     String str = null;
                     String strSpace = "";
                     StringTokenizer tokens;
                     BufferedReader br = new BufferedReader(new FileReader("C:\\tmp.txt"));
                     while(br.readLine()!=null)
                     {
                          str = br.readLine();                    
                     }
                     tokens = new StringTokenizer(str," ");
                     while(i < 4)
                     {
                          str = tokens.nextToken();
                          i++;
                     }
                     tokens = new StringTokenizer(str,",");
                     while(tokens.hasMoreElements())
                     {
                          strSpace += tokens.nextToken();
                     }
                     freeSpace = Integer.parseInt(strSpace);               
                }
                catch(Exception e)
                {
                     System.out.println("Exception:");
                     e.printStackTrace();
                }

      how do i convert the final strSpace value to integer?