当我有俄罗斯字母的文件时,它们看起来很好作为JFrame
的标题。但当我尝试在控制台中打印它们时,它会显示问题图标。有人能解释一下为什么会这样吗?也许有人有更简单的方法在俄语上获得头衔。
public class Main {
public static void main(String[] args){
File file = new File("1.txt");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
StringBuilder result = new StringBuilder();
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)){
int a = reader.read();
while(a!=-1){
result.append((char)a);
a = reader.read();
}
} catch (Exception e) {
e.printStackTrace();
}
JFrame frame = new JFrame(result.toString());
frame.setVisible(true);
frame.setSize(500, 500);
System.out.println(result.toString());
}
}
发布于 2021-07-28 21:22:36
这不是代码的问题,而是控制台的“问题”。控制台不知道您的俄语字符是什么意思,所以它会打印问号。另一方面,JFrame知道俄语符号,并且能够打印出来。
https://stackoverflow.com/questions/68561146
复制相似问题