我正在使用以下代码读取文本文件,
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;
}
关于Java : Skip Unicode characters while reading a file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56984774/