【发布时间】:2019-01-19 06:01:00
【问题描述】:
我制作了一个程序,它可以抓取网站并提取文本并将其写入 .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();
}
}
}
}
【问题讨论】:
-
您使用的是 MS Windows 吗?
标签: java cmd character-encoding fileoutputstream bufferedwriter