Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine encoding table of a text file

I have .txt and .java files and I don't know how to determine the encoding table of the files (Unicode, UTF-8, ISO-8525, …). Does there exist any program to determine the file encoding or to see the encoding?

like image 330
Ballon Avatar asked Nov 23 '10 10:11

Ballon


People also ask

How do I know if my file is UTF 16 or UTF-8?

There are a few options you can use: check the content-type to see if it includes a charset parameter which would indicate the encoding (e.g. Content-Type: text/plain; charset=utf-16 ); check if the uploaded data has a BOM (the first few bytes in the file, which would map to the unicode character U+FEFF - 2 bytes for ...

How do I know if a file is UTF-8?

Open the file in Notepad. Click 'Save As...'. In the 'Encoding:' combo box you will see the current file format. Yes, I opened the file in notepad and selected the UTF-8 format and saved it.

What is the encoding of a text file?

An encoding standard is a numbering scheme that assigns each text character in a character set to a numeric value. A character set can include alphabetical characters, numbers, and other symbols.


2 Answers

If you're on Linux, try file -i filename.txt.

$ file -i vol34.tex  vol34.tex: text/x-tex; charset=us-ascii 

For reference, here is my environment:

$ which file /usr/bin/file $ file --version file-5.09 magic file from /etc/magic:/usr/share/misc/magic 

Some file versions (e.g. file-5.04 on OS X/macOS) have slightly different command-line switches:

$ file -I vol34.tex  vol34.tex: text/x-tex; charset=us-ascii $ file --mime vol34.tex vol34.tex: text/x-tex; charset=us-ascii 

Also, have a look here.

like image 133
mpenkov Avatar answered Oct 04 '22 15:10

mpenkov


Open the file with Notepad++ and will see on the right down corner the encoding table name. And in the menu encoding you can change the encoding table and save the file.

like image 34
Ballon Avatar answered Oct 04 '22 15:10

Ballon