我想使用以下代码从 jar 文件创建 UTF-8 文件:
public class UTF8 {
public static void main(String[] args) throws Exception {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
"utf8.txt"), "UTF8"));
out.write("Look at this BASTÖÖÜÜÄÄ!");
}
}
这段代码使用 eclipse 运行得非常好。但如果我将其打包到 jar 文件中,它会使用依赖于平台的文件编码(例如 Windows 上的 Cp1252)。我能做什么呢?
最佳答案
在 Launch4j 的 JRE 选项卡上的 JVM 选项字段中(加载配置文件后)输入以下内容:
-Dfile.encoding=UTF8
或者,可以在应用程序的 ini 文件中指定相同的内容 - 请参阅以下位置的 launch4j 文档:
http://launch4j.sourceforge.net/docs.html#Additional_jvm_options
关于java - 从 jar 文件生成 UTF-8 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4280519/