4

I have a file encoded in UTF-8 which I want to read in java, change some things in the input and print the result to terminal (standard output) and to another file. I read and write the files and write to stdout with streams constructed to interpret UTF-8 encoding.

Everything is fine when I'm manually compiling and running everything, the output file contains UTF-8 signs, the stdout also prints them to terminal.

The problem is when I want to compile and run the program using ant. The output (written to terminal) produced by ant doesn't seem to use UTF-8 signs, as Polish diactrics are changed to '?'. Is there any way of forcing ant to use UTF-8? Also, can I check somehow which encoding is it using at present?

I searched for an answer, but all I found was how to make ant interpret UTF-8 encoded .java files.

2
  • 1
    You need to post your code. Ant is not a running environment. Ant is a fancy batch job that takes input and runs jobs/commands based on its configuration file. So running something by hand or in ant will result in the same output. Now if you're developing in one environment and running in another that can cause differences. Also ant could be picking up different libs than your dev env. End result. Post your code, build.xml, which libs you're using.
    – awm
    Nov 25, 2011 at 23:38
  • Thanks for the answer, problem is I needed it for my labs and now it's long gone. I didn't observe this page but the user question stats page and there was no notification of you replying here, as it's not a regular answer. Therefore I wasn't aware that you've asked me to show code/build.xml etc. I'm sorry, next time I'll be more careful. And don't take me as an ignorant that doesn't want to learn even later, but I got rid of the code and don't have any example to try your suggestions out.
    – Wojtek
    Feb 28, 2012 at 13:58

1 Answer 1

3

You could try setting -Dfile.encoding=UTF-8 this will set the encoding to UTF-8.

You may also want to check if your console encoding is UTF-8 (depends on the OS).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.