java - 从cmd运行时如何显示希腊字符
问题描述
我制作了一个程序,它可以抓取网站并提取文本并将其写入 .txt 文件。当我从 Intelij Idea 运行我的程序时,每一行都以希腊语正确打印。但是当我从 cmd 运行 jar 文件时,希腊文本被写成乱码。
public class Logger extends Thread{
String input,path;
int matchNumber;
public Logger(String path0) {
path=path0;
}
public void log (int matchesNumber0,String input0) {
matchNumber=matchesNumber0;
input=input0;
this.run();
}
@Override
public void run() {
BufferedWriter textWriter = null;
DateFormat date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date today = Calendar.getInstance().getTime();
String stringDateToday = date.format(today);
if(input!=null) {
try {
String logFilePath = path;
textWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFilePath), StandardCharsets.UTF_8));
textWriter.write(stringDateToday + "-----" + matchNumber + "-----");
textWriter.write(input + "\n");
if (!input.contains(" content=")) {
setWarningMsg(input);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Incorrect Log File path!!!");
} finally {
try {
textWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
解决方案
chcp 65001 && java -jar -Dfile.encoding=UTF-8 path/to/your/runnable/jar
这解决了我的问题!
推荐阅读
- python - 根据 pandas 数据框中的多个二级标签选择多索引列
- monads - “应用函子上的幺半群”与“内函子类别中的幺半群”有何不同?
- spring-boot - Spring Boot 可执行 JAR 无法将特权端口作为 systemd 服务打开
- java - Java保持最高数字
- go - 想法显示无法解析文件“fmt”
- django - Django rest 框架更新 Put 不允许
- css - 旋转圆圈 CSS
- php - 表单操作发生时 Laravel 回显自定义错误消息
- css - 导入 Materialize 源代码时的 Sass CompileError:Sass 映射“不是有效的 CSS 值”
- javascript - 如何添加过渡我的滑块?