java - Parse Integer error -


for reason cant string number value convert integer error run:

exception in thread "main" java.lang.numberformatexception: input string: "6327818260"     @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65)     @ java.lang.integer.parseint(integer.java:495)     @ java.lang.integer.parseint(integer.java:527)     @ mydirectory.getsize(mydirectory.java:18)     @ a19010.main(a19010.java:79) 

java result: 1

if input string "6327818260" why can't become integer? code is

public string getsize() {   int intsize = integer.parseint(mysize);   int count = 0;   string datatype = "";   while (intsize > 1000)   {       intsize = intsize / 1000;    count++;   }    switch (count)   {     case 0:     datatype = "bytes";     break;     case 1:     datatype = "kb";     break;     case 2:     datatype = "mb";     break;     case 3:     datatype = "gb";     break;     case 4:     datatype = "kb";     break;       }        return intsize + datatype ; }  

mysize taken part of string gotten text file here

 public class mydirectory  {   string myname = "" ;   string mynum = "";   string mysize = "";     public mydirectory(string line)    {     line = line.trim();       string[] lineparts = line.split(" ");      mysize = lineparts[0];      mynum = lineparts[1];      myname = lineparts[3];   } 

the line im splitting looks 6327818260 6486 sub-total: e:\wis26\lcorres

the largest possible integer 2147483647 deal less value you're trying parse: 6327818260

you need use long or biginteger/bigdecimal hold value.

for biginteger/bigdecimal strings representing base 10 integers can parsed constructors take string argument.

bigdecimal bigdecimal = new bigdecimal("6327818260"); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -