Java : Skip Unicode characters while reading a file

标签 java unicode

我正在使用以下代码读取文本文件,

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 
        }
    }
}

文本文件:

enter image description here

如何在读取文件时跳过所有 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/

相关文章:

java - 如果记录仅存在 13 个月,则检查数据库

java - Java中的HTML实体解码: apostrophe

java - 无法通过 Ingress Nginx Controller 进行 SSL 传递

c - 看看 C 中 WCHAR* 是否是 WCHAR 的子字符串

jquery - 使用 Jquery.serialize() 处理日语;

java - 使用 Spring validator 自定义 xsd 模式验证

Java并发实践: BoundedExecutor implementation

delphi - Delphi XE2 中的 UTF8Encode

php - 解决 UTF8 和法语口音不兼容问题

css - 使用 html5/css 堆叠字体符号并对齐字体周围的空格