Apache POI异常空白(已解决:\ u00A0非破坏空间)

时间:2015-06-03 21:00:46

标签: java apache-poi

编辑:已解决的答案:是一个00a0不间断的空间,而不是一个c0a0不间断的空间。

使用Apache POI将docx转换为纯文本,然后将明文读入Java并尝试解析它后,我遇到了以下问题。

输出:

" "
first characterequals SPACE OR TAB 
false
[B@5e481248
[B@66d3c617
ARRAYTOSTRING SPACE: [32]
ARRAYTOSTRING ?????: [-62, -96]

代码:

System.out.println("\t\"" + line.substring(0,1) + "\"\n\tfirst characterequals SPACE OR TAB \n\t" + (line.substring(0,1).equals(" ") 
                        || line.substring(0,1).equals("\t") ));
System.out.println(line.substring(0,1).getBytes());
System.out.println(" ".getBytes());
System.out.println("ARRAYTOSTRING SPACE: " + Arrays.toString(" ".getBytes()));
System.out.println("ARRAYTOSTRING ?????: " + Arrays.toString(line.substring(0,1).getBytes()));

String.trim()没有摆脱它 String.replaceAll(“\ s”,“”)没有摆脱它

我正在尝试解析一份巨大的材料文件,这正在成为一个主要障碍。我不知道发生了什么或者如何与它进行交互,是否有人能够了解这里发生的事情?

2 个答案:

答案 0 :(得分:2)

这转换为十六进制代码c2 a0的字节,根据this answer,它是一个UTF-8编码的非中断空格。请注意,实际上是一个空格,而\ s将不匹配。

答案 1 :(得分:0)

这对我有用:

~#