我想捕获这个异常,并且我想在 catch block 中进行一些处理,这是代码:
try {
root.setText(page.getText(field.getLine() + repetition,
field.getColumn(),
field.getLength()));
} catch (org.jdom2.IllegalDataException e) {
// ignore: some lines can be empty and cannot
// be a valid XML character so we skip them
String invalidStr = page.getText(field.getLine() + repetition, field.getColumn(),field.getLength());
}
这是我使用 e.printStackTrace() 时打印的错误;方法:
org.jdom2.IllegalDataException: The data "
" is not legal for a JDOM character content: 0x000c is not a legal XML character.
at org.jdom2.Text.setText(Text.java:182)
那么如何测试字符0x000c的值:
String invalidStr = page.getText(field.getLine() + repetition, field.getColumn(),field.getLength());
if (invalidStr.equals(???)) {
}
提前谢谢
最佳答案
if (invalidStr.indexOf(0x000C) >= 0) ...
或者
if (invalidStr.indexOf('\u000C') >= 0) ...
或者
if (invalidStr.contains("\u000C")) ...
(使用Unicode escape)
关于java - 测试十六进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23789112/