1
File folderPathFile = new File("C:\\Users\\ali\\Desktop\\folderPath.txt");


    BufferedReader reader = new BufferedReader(new FileReader(folderPathFile));
    String line = reader.readLine();
    while(line != null){
        foldersPath.add(line);
        line = reader.readLine();
    }
    reader.close();


    String lineDup = line.toString();
        String[] LineSplits = lineDup.split(",");


        String[] array = LineSplits[1].trim().split(" ");
        for(int i =0; i<array.length;i++) {
            int fr = Integer.parseInt(array[i]);
            System.out.println(fr);//its printing
        }

        int fr1 = Integer.parseInt(LineSplits[0]);
        System.out.println(fr1);
}                                            

My Problem is when i run this code i've java.lang.Exception: java.lang.NumberFormatException: For input string: "900"

INPUT i'm Giving i.e myfile data is 900, 200 300 400 500 600

Why for 900 only i'm getting such error ?

11
  • 3
    I don't know how your code is running with arrayi] Commented Jul 17, 2015 at 17:03
  • int fr = Integer.parseInt(array[i]);//correct Commented Jul 17, 2015 at 17:04
  • LineSplits[0] length is 4 why ? Commented Jul 17, 2015 at 17:06
  • No LineSplits[0].length() is 3 only. Commented Jul 17, 2015 at 17:10
  • 1
    @Satya It's 4 and Ankur's answer worked .. i wrote the line again and everything Worked :) Commented Jul 17, 2015 at 17:19

2 Answers 2

2

Check for the lineSplit[0] length if it's 4 then there is an invisible character i.e ZERO WIDTH NO-BREAK SPACE . It's hard to detect as it's invisible and trimming won't delete that character. If so you need to get rid of that character

EDIT: As you are Saying it's length is 4. try this LineSplits[0].replace(u'\ufeff', '') or You can write that number yourself instead of copying it from somewhere

You can check the long discussion about this character here on this SO Question though it's regarding HTML but makes sense how this character comes and all

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

2 Comments

Yes it's showing 4 how to get rid of that Character ?
Worked Like ANYTHING .. I never realized this can also Happen .. Thank you :)
0

If you are newbie to MapReduce programming and just learning from sample input file that you have copy pasted from the web then just create input file manually as during copy paste some UTF characters also get pasted.

I solved the issue by manually creating sample file.

Comments

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.