-1

In Java I try to convert a string value into an integer, removing the 4 last characters, so I tried like that :

 String filename1="98597598684.txt";
 int id = Integer.parseInt(filename1.substring(0,  filename1.length()-4));

but I get this error, and I don't understand why :

 java.lang.NumberFormatException: For input string: "98597598684"
at java.lang.NumberFormatException.forInputString(Unknown Source)

it's probably sthg simple but that makes me crazy since 1 hour, any idea?

2

2 Answers 2

6

98597598684 is greater than Integer.MAX_VALUE. Use

long id = Long.parseLong(filename1.substring(0, filename1.length() - 4));
Sign up to request clarification or add additional context in comments.

Comments

1

you can even try new BigInteger("98597598684")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.