2

So the issue I am getting seems to be a kind of common, however the missing points in each of the issues I checked online was different from the one I experiencing.

So what I am trying to do is converting a string back to long. The string was read from a file as following

484625517161611266 string 454511457536

I read the line into an array and I printed the array which shows the writing went fine. Then I tried convert to long as below

long id = Long.parseLong(splitted[0],10);

However I got this issue

java.lang.NumberFormatException: For input string: "484625517161611266"

Normally the common issues with this type of exception would be trying to convert letter or trying to convert numbers that contains spaces. Another issue might be a certain mistake while reading the file.

However I check all of those possibilities and still I am getting this exception

Any Suggestions ? Thanks in advance

3
  • The FEFF is even in the string up there in the question, in the error message! ROFL. Commented Dec 31, 2014 at 18:38
  • It's the very first character. Commented Dec 31, 2014 at 18:41
  • The FEFF character is a byte order mark. Commented Dec 31, 2014 at 20:18

1 Answer 1

5

java.lang.NumberFormatException: For input string: "484625517161611266"

There is a \uFEFF (ZERO WIDTH NO-BREAK SPACE) character in your input

Try copying it and pasting it in plain text editor, remove this junk character

to remove this character you can use

inputNumberString.replaceAll("\uFEFF", "").trim()

note: trim() just to remove any other whitespace if present

Sign up to request clarification or add additional context in comments.

11 Comments

I don't think trim will take care of that.
yes and that is why and remove this junk character
It reads as if trim() will fix it. And if not, it's just some random extra advice :p Good catch though btw.
would it be possible to remove the "/uFEFF" character using .replace function ?
plz take your discussion to a chat room
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.