Hiển thị các bài đăng có nhãn i18n. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn i18n. Hiển thị tất cả bài đăng

How to check whether text file is encoded in UTF-8 or ANSI or anything else?

Problem : How to check whether text file is encoded in UTF-8 or ANSI?
Solution : A very simple solution for Windows environment without using any extra software.

Method 1 : Open the file in notepad(Windows default text editor)
Now Click on 'Save As' in File menu.
The 'Encoding' combo box will tell you the current file encoding.

File Encoding
File Encoding
Method 2 : Second method requires a third party software, Notepad++.
Open the file in question with Notepad++.
At the bottom right of the editor, it will show the current encoding of the file.

File Encoding Notepad++
File Encoding Notepad++

Specify non-ASCII characters in a file : i18n

You can specify Unicode character with following escape sequence
\u XXXX
where XXXX refer to 4 hexadecimal digits representing value of the UTF-16 code unit.

E.g. a properties file might have the following entries:
s1=hello there
s2=\u3053\u3093\u306b\u3061\u306f

In order to convert a file saved in non-ASCII encoding to ASCII, you can use native2ascii tool, found in <jdk>\bin
non-ASCII
non-ASCII
native2ascii [options] [inputfile [outputfile]]

Description
The Java compiler and other Java tools can only process files which contain Latin-1 and/or Unicode-encoded (\udddd notation) characters. native2ascii converts files which contain other character encodings into files containing Latin-1 and/or Unicode-encoded charaters.

If outputfile is omitted, standard output is used for output. If, in addition, inputfile is omitted, standard input is used for input.

Options : 
-reverse
Perform the reverse operation: convert a file with Latin-1 and/or Unicode encoded characters to one with native-encoded characters.

-encoding encoding_name
Specify the encoding name which is used by the conversion procedure. The default encoding is taken from System property file.encoding. The encoding_name string must be taken from the first column of the table of supported encodings in the Supported Encodings document.

-Joption
Pass option to the Java virtual machine, where option is one of the options described on the reference page for the java application launcher. For example, -J-Xms48m sets the startup memory to 48 megabytes.

Source : Here