11

I use weird Unicode strings in my Java test cases. The compiler seemingly interprets the file as iso-8859-1, causing JUnit to complain.

In Python I can specify the encoding at the top of the file:

# -*- coding: utf-8 -*-

Is there an equivalent in Java? How can I detect / specify the encoding of .java files?

Frederik
  • 14,156
  • 10
  • 45
  • 53

3 Answers3

7

You can set it when you compile the file with the parameter "-encoding"

http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html

Frederik
  • 14,156
  • 10
  • 45
  • 53
Figus
  • 681
  • 1
  • 7
  • 13
3

The javac compiler has a parameter -encoding where you can set it. In Eclipse you must change the project settings or the global settings for *.java files.

A.H.
  • 63,967
  • 15
  • 92
  • 126
3

The java compiler (javac) accepts an option -encoding. If you are using an IDE like Eclipse you can specify the encoding in the preferences.

Stefan
  • 4,645
  • 1
  • 19
  • 35