我正在使用以下代码读取文本文件,
try (BufferedReader br = new BufferedReader(new FileReader(<file.txt>))) {
for (String line; (line = br.readLine()) != null;) {
//I want to skip a line with unicode character and continue next line
if(line.toLowerCase().startsWith("\\u")){
continue;
//This is not working because i get the character itself and not the text
}
}
}
文本文件:
如何在读取文件时跳过所有 unicode 字符?
请您参考如下方法:
您可以跳过所有包含非 ASCII 字符的行:
if(Charset.forName("US-ASCII").newEncoder().canEncode(line)){
continue;
}