Intellij构建工件 – 可运行的JAR UTF-8

huangapple go评论83阅读模式
英文:

Intellij build artifact - runnable jar UTF-8

问题

我创建了一个项目,用于读取一个保存为CSV UTF-8格式的CSV文件。
在我的项目中,我读取了该CSV文件的每一行。
每一行的输出都显示在一个日志文件中。

现在,当我在IntelliJ中运行我的项目并查看日志文件时,所有行都是可读的。
但是,当我从项目构建一个artifact,然后运行那个jar文件时,CSV中的一些符号被一个'?'符号替代了。。

我查看了项目的设置,文件编码是UTF-8。

我不知道如何可能出现这种情况。有人能帮帮我吗?谢谢!

英文:

I builded a project that reads a csv file (saved as csv UTF-8).
in my project i read every line of that csv file.
The output of every line is displayed in a log file.

Now when i run my project in intellij and i look into the log file all the lines are readable.
But when i build an artifact from my project and then run that jar some symbols that are in the csv are replaced by a '?' symbol ..

i looked into the settings of my project under file encoding and there is everything UTF-8 also.

I have no clue how that is possible ..
Can anyone help me out ? Thx !

答案1

得分: 1

指定在命令行中运行应用程序时的编码,例如:

java -Dfile.encoding=UTF-8 -jar yourapp.jar param1 param2

或者修改您的应用程序代码,以显式强制正确的编码来读取/写入文件。

英文:

Specify the encoding when running the app from the command line like this:

java -Dfile.encoding=UTF-8 -jar yourapp.jar param1 param2

Or change your app code that reads/writes files to explicitly force the correct encoding.

答案2

得分: 0

当我指定 -Dfile.encoding=UTF-8 时,我需要将这个编码选项放在两个"之间,但是它不起作用,并返回一个错误。也许这会帮助有相同问题的人。

java "-Dfile.encoding=UTF-8" -jar app.jar
英文:

When I specify -Dfile.encoding=UTF-8, I need to put this encoding option between two " however it doesn't work and an error is returned. Maybe it will help somebody with the same problem as me.

java "-Dfile.encoding=UTF-8" -jar app.jar

huangapple
  • 本文由 发表于 2020年10月15日 04:55:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/64361367.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定