【发布时间】:2015-04-01 17:25:05
【问题描述】:
以下代码完美适用于具有英文内容的文件,但不适用于俄语内容。如何让它也适用于俄语?
try(BufferedReader fileOut = new BufferedReader(new FileReader(file))){
for(String line; (line = fileOut.readLine()) != null; ){
if(line.contains(commandString))
System.out.println(count + ": " + line);
count++;
}
}
UPD:
我试图写:这仅在该行包含一个单词然后输出时才有效,例如:“привет” 如果一行包含多个单词则没有输出,例如“привет как дела”
new BufferedReader(new InputStreamReader(new FileInputStream(file), "Cp1251"))
p.s: 非常感谢您的回答
【问题讨论】:
-
我的第一个猜测是
commandString值的代码页与文件内容的代码页不匹配。您可能应该提供更多信息,例如示例数据。 -
文件使用什么字符编码?
标签: java regex bufferedreader