Learning Java. Created a project using Maven. I make a conclusion to the console of certain information in Russian + I write the same information to a file. When I launch IDEA, everything is fine, everything works as it should. Russian text in the file and in the console is displayed normally. But when I compile to jar, I run java -jar myprogramm.jar from the Windows console, the output to the console is normal, and writes this to the file

GARDEN, 42, 620024 ESTIMATE, COMPOSITION

For some reason, the file is saved in windows 1252 encoding (at least this is indicated by sublime).

mavena settings

 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 

I FileWriter writer = new FileWriter(stringDate() + ".txt", true) to the file via FileWriter writer = new FileWriter(stringDate() + ".txt", true)
When I do through PrintWriter writer = new PrintWriter(new File(stringDate() + ".xml"), "UTF-8"); where I forcibly specify UTF-8, then everything is fine, but there is no append method in PrintWriter .

Tell me how to get out of this?

Later tried to add to the maven

 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 

the file is created in UTF-8, but Russian characters are replaced by question marks ????
I don’t know what to do, thanks for any help.

  • I apologize, but what kind of format is this "eche"? Perhaps "txt"? And that's the whole problem? - DenShDen
  • This I accidentally wrote, in the project txt - Tryserg

1 answer 1

Cured a problem with

 OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(stringDate() + ".txt", true),"UTF-8"); 
  • It would also help: -Dfile.encoding = UTF-8 or so System.setProperty ("file.encoding", "UTF-8"); and you can not give the encoding in the writer - Vladislav Pyatkov
  • -Dfile.encoding = UTF-8 when compiling in the IDEA console, it was mentioned that the mole will be used by default. But System.setProperty ("file.encoding", "UTF-8"); I think it will hardly help, since <project.reporting.outputEncoding> UTF-8 </project.reporting.outputEncoding> does the same, the file becomes UTF-8, but question marks appear in the inside. But thanks, I will check and test. I think I will find the best option - Tryserg
  • Not at the assembly, and at start I had to enter. - Vladislav Pyatkov