【发布时间】:2021-10-04 05:44:12
【问题描述】:
当我有带有俄语字母的文件时,它们看起来像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());
}
}
【问题讨论】:
-
我认为控制台只支持非特殊字符。这可能就是原因。
-
问题是控制台使用的字体不支持这些字符。控制台与应用程序的用户无关,所以我看不出这有多重要。
标签: java swing jframe tostring