StringIndexOutOfBoundsException Error

前端 未结 1 1725
予麋鹿
予麋鹿 2021-01-29 06:03

I want to parse a numeric file. I achieve parsing but when I changed the file content, I get a StringIndexOutOfBoundsException. Any help will be appreciated.

My code is

相关标签:
1条回答
  • 2021-01-29 07:09

    The only thing here, which can throw an IndexOutOfBoundsException is the

    s.charAt(0)
    

    code.

    That means that in this line on the first position there is nothing = empty line.

    Try the following in the beginning of your loop:

    if(s == null || s.trim().length() == 0)
    {
        System.out.println("Empty line found.");
        continue;
    }
    
    0 讨论(0)
提交回复
热议问题