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

Viewed 23196

"out.txt" content is

1

My JAVA code is like this.

    int val=0;
    BufferedReader br = new BufferedReader(new FileReader("out.txt"));

    while(true) {
        String line = br.readLine();
        if (line==null) break;
        val=Integer.parseInt(line);
    }
    br.close();

and debugger says,

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

i need to use 1 from "out.txt". How can i use 1 as Integer? Thank you for your attention :)

3 Answers

I removed this invisible Unicode character and now parsing to INT works great. I know it's not the case here but maybe can help some other people.

text = text.replaceAll("\\uFEFF", "");
Related