Java Parse对excel获取的字符串抛出NumberFormatException

Java Parse对excel获取的字符串抛出NumberFormatException,java,excel,Java,Excel,在我的程序中,我获取Excel表格的每一行。拆分行时,为了将数组的每个字符串解析为一个整数,将抛出标题中提到的异常。该表以以下方式填充: 0;1;100;4;1000;8;8 ... 表格保存为.csv,这就是我按拆分的原因 Idea:文件值包含假字符: 我已经检查了0-width字符 代码片段: try { bufferedReader = new BufferedReader(new FileReader(fileName)); while ((line

在我的程序中,我获取Excel表格的每一行。拆分行时,为了将数组的每个
字符串
解析为一个
整数
,将抛出标题中提到的异常。该表以以下方式填充:

0;1;100;4;1000;8;8
...
表格保存为
.csv
,这就是我按
拆分的原因

Idea:文件值包含假字符:
我已经检查了0-width字符

代码片段:

try {
        bufferedReader = new BufferedReader(new FileReader(fileName));

        while ((line = bufferedReader.readLine()) != null) {
            if(flag == 0){
                tableSize = line.split(";").length;
                System.out.println("TableSize is: "+tableSize);
                flag = 1;
                table1 = new int[tableSize][tableSize];
            }
            String [] tempStrings = line.split(";");
            int [] tempInts = new int[tableSize];

            for(int i=0; i<tableSize;i++){
                tempInts[i] = Integer.parseInt(tempStrings[i]);
                System.out.println(tempInts[i]);
            }

            table1[row] = tempInts;
            row++;
        }

您的CSV文件以UTF-8编码的文件开头。例如,如果在十六进制编辑器中打开文件,您可以看到它:

虽然额外的字节EF BB BF不可见,但它们是令Integer.parseInt感到不安的


请参阅以获取一些解决方案。

尝试捕获异常并在catch{}中打印字符串打印的字符串为“0”@Alan,这意味着输入字符串的异常消息为“0”
?你确定它是零而不是O吗?是的,我检查了它(并替换了它)
Integer。parseInt(“0”)
永远不会抛出异常。某些字符串中一定有伪字符,或者字符串是空的,或者其他什么。
java.lang.NumberFormatException: For input string: "0"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at excercise.Main.fillTableByCsv(Main.java:53)
at excercise.Main.main(Main.java:22)