Download Caxton for Free · 7-day free trial of Caxton Pro, no credit card required · 8 MB · macOS 13.0+
The short answer
To open a UTF-16 or Shift-JIS file on a Mac, tell the program which encoding the file is in, because the bytes are intact and only the reading is wrong. In TextEdit, choose File, then Open, select the file, click Show Options and pick the encoding from the Plain Text Encoding menu, or write a UTF-8 copy in Terminal with a command such as iconv -f CP932 -t UTF-8 customers-cp932.csv > customers-utf8.csv, where UTF-16 takes the place of CP932 for a UTF-16 file that starts with a byte order mark. Caxton, a native Mac editor for text and data files, detects UTF-16 and Shift-JIS as the file opens and names the encoding in a banner, and when the text is still wrong you choose File ▸ Reopen with Encoding ▸ UTF-16 LE, UTF-16 BE or Shift-JIS, which reads the same bytes again and changes nothing on disk.
Why is a UTF-16 file or Japanese text garbled on a Mac?
A text file is a run of bytes, and an encoding is the rule that turns those bytes into characters. A file written in UTF-16 or Shift-JIS holds its characters as different bytes from the same text in UTF-8, so a program that expects UTF-8 or a Western encoding shows the wrong characters. Read as Windows-1252, the Shift-JIS bytes for 日本語 come out as “ú–{Œê, and the bytes for テスト come out as ƒeƒXƒg. The bytes are intact, and the text comes back the moment they are read with the right rule.
UTF-16 stores text in units of two bytes, so in English text every letter sits beside a zero byte. Windows is a common source. Microsoft's PowerShell documentation states that "In general, Windows PowerShell uses the Unicode UTF-16LE encoding by default," and that using a Unicode encoding there "always creates a BOM." LE stands for little-endian, the byte order in which the low byte of each unit comes first, and BE for big-endian, the opposite order. The BOM is the byte order mark, a signature at the start of the file that tells a reader which order the file uses. The Unicode Consortium's FAQ lists its bytes: FF FE for little-endian UTF-16 and FE FF for big-endian.
Shift-JIS is a Japanese encoding in which a kanji or a full-width kana takes two bytes. What Windows writes is its own extension of the standard, code page 932, which Microsoft's list of code pages names "ANSI/OEM Japanese; Japanese (Shift-JIS)." Its registration with IANA, under the name Windows-31J, describes it as "A variant of Shift_JIS to include NEC special characters (Row 13), NEC selection of IBM extensions (Rows 89 to 92), and IBM extensions (Rows 115 to 119)," and adds that such text "is commonly declared with the shift_jis name of the parent charset." A file that someone calls Shift-JIS is therefore often code page 932, and the difference decides whether characters such as ①, ㈱ and 髙 survive a conversion.
This guide is about reading such a file correctly. If a program has already saved the wrong reading, so that the file itself now holds the garbled characters, fix garbled text and the wrong encoding covers the repair.
How do I tell whether a file is UTF-16 or Shift-JIS?
Start with file, which is included with macOS. Its manual page describes the -I option as one that makes it "output mime type strings rather than the more traditional human readable ones," and the answer ends with a charset. Seven small files were built for this guide: a tab-delimited export in UTF-16 that starts with a byte order mark, the same export without the mark, a diary entry in UTF-16 without a mark that is almost all Japanese, meeting minutes in plain Shift-JIS, a customer list in code page 932, and the minutes again in EUC-JP and in ISO-2022-JP, two other Japanese encodings.
file -I report-utf16.txt report-nomark.txt diary-nomark.txt minutes-sjis.txt customers-cp932.csv minutes-eucjp.txt minutes-jis.txt
report-utf16.txt: text/plain; charset=utf-16le
report-nomark.txt: application/octet-stream; charset=binary
diary-nomark.txt: application/octet-stream; charset=binary
minutes-sjis.txt: text/plain; charset=unknown-8bit
customers-cp932.csv: text/csv; charset=unknown-8bit
minutes-eucjp.txt: text/plain; charset=iso-8859-1
minutes-jis.txt: text/plain; charset=us-ascii
Only the first answer names the real encoding, and it rests on the byte order mark. Without the mark, file reports both UTF-16 files as binary. The Shift-JIS file and the code page 932 file get unknown-8bit, which means only that they are neither ASCII nor UTF-8. EUC-JP gets a Western name. The ISO-2022-JP file is reported as ASCII, which is true of its bytes and no help in reading it. For that last file the same tool gives a better clue without -I.
file minutes-jis.txt
minutes-jis.txt: ASCII text, with escape sequences
ISO-2022-JP switches between ASCII and Japanese with the escape character, so that answer on a file you expect to be Japanese points to it.
For UTF-16 the bytes themselves settle the question. xxd prints them in hexadecimal, and -l 16 stops it after the first sixteen.
xxd -l 16 report-utf16.txt
xxd -l 16 report-nomark.txt
xxd -l 16 diary-nomark.txt
00000000: fffe 6900 6400 0900 6e00 6100 6d00 6500 ..i.d...n.a.m.e.
00000000: 6900 6400 0900 6e00 6100 6d00 6500 0900 i.d...n.a.m.e...
00000000: ca4e e565 6f30 1d67 4b30 8930 e896 4c30 .N.eo0.gK0.0..L0
The first file starts with FF FE, the mark of little-endian UTF-16. The second has no mark, and the pattern gives it away all the same: each letter is followed by a zero byte, 69 00 for i and 64 00 for d. In big-endian UTF-16 the zero comes first. The third file is UTF-16 as well, and there is not one zero among the bytes shown, because a Japanese character uses both bytes of its unit. Such a file has neither a mark nor a pattern of zero bytes to recognize it by, and that matters for every tool in this guide.
So read the charset from file as a hint. An answer of utf-16le or utf-16be can be trusted. An answer of binary for a file you know is text suggests UTF-16 without a mark. An answer of unknown-8bit or iso-8859-1 for a Japanese file leaves the question open, and where the file came from is the better clue: a file from a Japanese Windows system is most likely code page 932.
How do I open a UTF-16 or Shift-JIS file in TextEdit?
TextEdit is included with macOS, and it lets you choose the encoding at the moment you open a file. Apple's TextEdit User Guide explains that "By default, TextEdit uses its automatic text encoding to display documents," and continues: "If characters aren’t appearing correctly, try choosing a different encoding when you open the file." These are the steps in Apple's words:
- "choose File > Open, then select the file (don’t open it)."
- "Click Show Options in the lower left of the window."
- "Click the Plain Text Encoding pop-up menu and choose an encoding."
- "Click Open."
If the encoding you need is missing from the menu, the guide's advice is to "choose Customize Encodings List, then select the encodings to include." Apple's page does not list the encodings by name, so look in that menu for the UTF-16 and Japanese entries. For a short file that you only need to read, this is the quickest route, and nothing has to be installed.
How do I convert a UTF-16 file to UTF-8 with iconv?
iconv is included with macOS. In the words of its manual page it "converts the codeset of file" from the name you give with -f to the name you give with -t. Each command below writes a new file and leaves the original alone. The name to give for UTF-16 depends on the byte order mark.
iconv -f UTF-16 -t UTF-8 report-utf16.txt > report-utf8.txt
iconv -f UTF-16LE -t UTF-8 report-nomark.txt > report-nomark-utf8.txt
iconv -f UTF-16BE -t UTF-8 report-be.txt > report-be-utf8.txt
The first line is for a file that starts with a mark. iconv reads the mark, takes the byte order from it and leaves it out of the result. The second and third lines are for files without a mark, where you supply the order yourself. In the tests for this guide all three results held the same four lines of text.
The mistake to avoid is the plain name UTF-16 on a file that has no mark. The Unicode Consortium's FAQ gives the reason: the unmarked form "uses big-endian byte serialization by default," and Windows tools such as PowerShell write little-endian. Here is the diary entry converted that way.
iconv -f UTF-16 -t UTF-8 diary-nomark.txt
쩎漰ᵧ䬰褰䰰䶖挰昰䐰縰地弰Ȱ얙縰朰楫䐰昰İ䐰搰舰渰ﮖ쪎欰坎訰縰地弰Ȱ䡓豟漰ᩏ炋䰰豎搰䈰訰İぞ訰漰䖐估樰訰縰地弰Ȱ
No error was reported, and the exit status was 0. Every unit was read with its two bytes swapped, which turns Japanese into unrelated characters, many of them Korean and Chinese. With -f UTF-16LE the same file begins 今日は朝から雨が降っていました。 On the tab-delimited export the same mistake stopped part of the way through with Illegal byte sequence. In both cases, read the result before you rely on it. How to convert a file to UTF-8 on a Mac covers the byte order mark in the result, a whole folder of files, and Windows-1252.
Shift-JIS or CP932: which name do I give iconv?
The minutes hold only characters of the Shift-JIS standard, and the standard name converts them.
iconv -f SHIFT_JIS -t UTF-8 minutes-sjis.txt > minutes-utf8.txt
The customer list was written the way Windows writes it, in code page 932, and three of its characters exist only there: 髙 in a family name, ㈱ in a company name, and ① in a note. Read correctly, the file holds these four lines.
番号,氏名,会社,メモ
1,髙橋 健,㈱見本商事,資料は C:\data\list.txt
2,佐藤 花子,テスト工業,納期は①案で 10~20 個
3,田中 一郎,サンプル電機,デンワ希望
Under the standard name the conversion stops at the first of those characters.
iconv -f SHIFT_JIS -t UTF-8 customers-cp932.csv > customers-wrong.csv
iconv: iconv(): Illegal byte sequence
The new file ends after 1, on its second line, where 髙 should be. It is tempting to add -c, which the manual page describes with the words "Prevent output of any invalid characters." The command then finishes without a message.
iconv -c -f SHIFT_JIS -t UTF-8 customers-cp932.csv
番号,氏名,会社,メモ
1,橋 健,見本商事,資料は C:¥data¥list.txt
2,佐藤 花子,テスト工業,納期は案で 10〜20 個
3,田中 一郎,サンプル電機,デンワ希望
Three things are wrong with this result, and nothing reported them. The characters 髙, ㈱ and ① are gone, so the first customer is now named 橋 健. Both backslashes in the Windows path became yen signs, because iconv reads the byte 5C as ¥ under SHIFT_JIS and as a backslash under CP932. And the ~ between 10 and 20 became 〜, a different character. The Windows-31J registration covers the second point: "In practice 0x5C in Windows-31J is mapped to U+005C in Unicode, but usually displayed as a yen sign glyph." The name that matches the file converts all of it.
iconv -f CP932 -t UTF-8 customers-cp932.csv > customers-utf8.csv
The result is the four lines shown above, with every character in place. CP932 also converted the plain Shift-JIS minutes to exactly the same text as SHIFT_JIS did, so for a file that came from Windows, try CP932 first.
To find the name iconv uses for an encoding, filter the list that iconv -l prints. Each line of the answer is one encoding under all of its names.
iconv -l | grep -i -E 'sjis|932|euc-jp|2022-jp'
CP51932 51932 MS51932 MSCP51932 WINDOWS-51932
CP932 932 CSWINDOWS31J MS932 MSCP932 SHIFT_JIS-MS SJIS-MS SJIS-OPEN SJIS-WIN WINDOWS-31J WINDOWS-932
EUC-JP-MS EUCJP-MS EUCJP-OPEN EUCJP-WIN EUCJPMS
EUC-JP CSEUCPKDFMTJAPANESE EUCJP IBM-EUCJP
ISO-2022-JP-1 ISO2022-JP1
ISO-2022-JP-2 CSISO2022JP2 ISO2022-JP2 ISO-2022-JP-2004 ISO-2022-JP-3 ISO2022-JP2004 ISO2022-JP3
ISO-2022-JP CSISO2022JP ISO2022-JP
SHIFT_JIS CSSHIFTJIS MS_KANJI SHIFT-JIS SJIS
CP932, WINDOWS-31J and SJIS-WIN are one encoding, and SHIFT_JIS and SJIS are another. The two other Japanese encodings convert the same way under their own names.
iconv -f EUC-JP -t UTF-8 minutes-eucjp.txt > minutes-euc-utf8.txt
iconv -f ISO-2022-JP -t UTF-8 minutes-jis.txt > minutes-jis-utf8.txt
iconv is the better tool when the same conversion has to run on many files or on a schedule. Its limit is that it trusts the name you give it, and each wrong guess is another file to open and read.
How do I open a UTF-16 or Shift-JIS file in Caxton?
Caxton decides the encoding as the file opens, shows what it decided and why, and lets you overrule it without touching the file. Each step below names the tier it needs.
1. Open the file and read the banner
Drag the file onto Caxton, or choose File ▸ Open… and pick it. A file that is not UTF-8 opens with a banner in the status bar that names the encoding, and there are two kinds of banner.
- When Caxton is sure, as it is for a UTF-16 file with a byte order mark, this banner appears for a few seconds: This file is UTF-16 LE. You are editing a UTF-8 working copy, and Save converts it back.
- When its confidence is under 90%, this banner appears and stays: Detected: Shift-JIS (85%). Reopen with different encoding? (File ▸ Reopen with Encoding)
A Shift-JIS file always gets the second kind. Shift-JIS has no mark, so Caxton finds it by scoring how the bytes read as Japanese text, and an encoding found by scoring is never given more than 85%. The banner is a reminder to look at the text, and when the text reads correctly there is nothing more to do. Opening and reading are Caxton Free at any file size.
2. Check the reason in the Inspector
Choose View ▸ Show Inspector, or press ⌥⌘I. The Encoding section has an Encoding row, a Confidence row, a BOM row that shows Present or None, and a row named Why this encoding that gives the evidence in a sentence or two. For the sample files of this guide the row holds one of these:
- Caxton read this file as UTF-16 LE because it starts with the UTF-16 LE byte-order mark.
- Caxton read this file as UTF-16 LE because it has no byte-order mark and every other byte is zero, which is the pattern of UTF-16 text.
- Caxton read this file as UTF-16 LE because it has no byte-order mark, it is not valid UTF-8, and its bytes read in pairs as UTF-16 text in that byte order.
- Caxton read this file as Shift-JIS because it is not valid UTF-8 and its bytes fit Japanese text best. GB18030 was the next closest.
After a sentence of the last kind, a second one names the encoding that came next, and that encoding is the first one to try if the text looks wrong. A Working copy row appears for every file that is not UTF-8. The Invalid bytes row counts the bytes that could not be read in the encoding, each of which Caxton shows as a replacement character, and its First and Next buttons jump to them. The Inspector is Caxton Free at any file size.
3. Reopen with Encoding when the text is wrong
File ▸ Reopen with Encoding lists 18 encodings. The ones for the files in this guide are UTF-16 LE, UTF-16 BE, Shift-JIS and EUC-JP. Choose one, and Caxton reads the file from disk again in that encoding. While the confidence is under 90%, the Encoding section of the Inspector also has a Reopen with Encoding… button, which opens the same list. Three kinds of file need this step.
- UTF-16 with no mark that the bytes do not give away. Caxton recognizes unmarked UTF-16 in two ways. Text that is mostly ASCII has a zero byte beside each character. Text that is mostly Japanese, Chinese or Korean is read two bytes at a time in both byte orders, and Caxton names UTF-16 when one order gives text and the other gives characters that text never holds. The diary sample opens that way as UTF-16 LE at 85%, readable, with the Detected banner. Neither test settles unmarked UTF-16 that is mostly in another script, such as Cyrillic, Greek, Arabic, Thai or Hindi, because such text reads as plausibly in the wrong byte order. A very short file can fail the second test as well, because the test needs a line break and one more ASCII character, or sixteen ASCII characters, and at least two characters that cannot be text in the other order. Choose UTF-16 LE for a file from Windows, and UTF-16 BE if that reads wrong.
- Japanese with no kana. Caxton tells Japanese from Chinese by the kana in the text. A list of names written only in kanji can open as GB18030, with a Japanese encoding named as the alternative in the Inspector. Choose Shift-JIS or EUC-JP.
- A short Shift-JIS file with a damaged byte. Caxton still detects Shift-JIS when the first 256 KB of the file hold up to eight bytes that are not valid in it and at least 100 Japanese letters for each of them, and it then gives the encoding ten points less. A short file is outside that allowance. The minutes sample holds 30 such letters, so with one damaged byte it is not detected as Shift-JIS and opens unreadable in another encoding, with the Detected banner. Choose Shift-JIS. Each damaged byte then shows as a replacement character, and the Invalid bytes row of the Inspector takes you to it.
Reopening changes how the bytes are read and never the bytes, so the file on disk stays exactly as it was. If the document has unsaved edits, Caxton first asks whether to reopen and discard them, because the file is read from disk again. An encoding you choose wins over a byte order mark. Afterwards the Inspector marks the encoding as chosen and shows Set by you in the Confidence row. The choice comes back with the window when Caxton restores your session. A file that you open fresh is detected again, so for an export that arrives every week, Edit ▸ File Pattern Rules… has an Encoding menu that sets the encoding for every file whose name matches a pattern. Reopen with Encoding and File Pattern Rules are Caxton Free at any file size.
4. Edit and save in the file's own encoding
While the file is open you work on the UTF-8 working copy, and ⌘S converts it back. A UTF-16 file is written as UTF-16 in the same byte order, with a byte order mark if it had one and without if it had none. A Shift-JIS file is written as Shift-JIS, with one detail worth knowing. Code page 932 gives some characters two byte codes, and Caxton writes one of them whichever the file had. In the customer list, 髙 arrived as the bytes FB FC and is saved as EE E0. Both codes read as 髙 under code page 932, so the text is unchanged, but those bytes are not what they were. UTF-16 can hold every character, so a save into it is never refused over a character. Shift-JIS cannot. If you have typed something it has no bytes for, such as an emoji or an accented Latin letter, Caxton saves nothing and asks, under the title Can't save in Shift-JIS, whether to save as UTF-8 instead. Save as UTF-8 changes the file's encoding on disk, and Cancel leaves the file as it was so that you can take the character out.
Editing in the text view and saving are Caxton Free for a file of up to 10 MB. The limit is measured on the file as it is on disk, not on the working copy. A larger file needs Caxton Pro, which every download includes as a 7-day free trial of Caxton Pro with no credit card required. Editing in the table is Caxton Pro at any size.
5. Keep a UTF-8 copy, or convert the file itself
Two commands change the encoding on purpose. File ▸ Save As… on a file that opened as UTF-16 or Shift-JIS writes a UTF-8 copy and leaves the original alone, and a line in the save panel confirms it before you click: Saves a UTF-8 copy. The original file is Shift-JIS. File ▸ Save with Encoding… converts the file itself. Its form has an Encoding menu with the same 18 encodings and a checkbox named Start the file with a byte order mark, which is a choice for UTF-16 only. Caxton first makes sure that every character can be written in the encoding you chose, and it saves nothing if one cannot. Both commands are Caxton Free for a file of up to 10 MB and Caxton Pro above that. How to convert a file to UTF-8 on a Mac walks through the form and its checks.
Which encodings does Caxton detect, and which do I choose by hand?
The table lists every encoding under the name Caxton gives it in the Reopen with Encoding menu, the banner and the Inspector. The two UTF-32 forms are detected and are not in the menu, and ISO-2022-JP is not read at all.
| Encoding | When the file opens | In Reopen with Encoding |
|---|---|---|
| UTF-16 LE and UTF-16 BE with a byte order mark | Detected from the mark, FF FE or FE FF, at 100%. | Listed. |
| UTF-16 LE and UTF-16 BE without a mark | Detected by its zero bytes when more than half of the characters in the first 256 KB are ASCII, at a confidence between 85% and 95%. Text that is mostly Japanese, Chinese or Korean is detected by reading its bytes in pairs, at 85%, or at 75% when a damaged pair was passed over. Text that is mostly in another script, such as Cyrillic, Greek, Arabic, Thai or Hindi, is not recognized. | Listed. You choose the byte order. |
| UTF-32 LE and UTF-32 BE | Detected from the byte order mark only. | Not listed, so a UTF-32 file without a mark cannot be read as UTF-32. |
| Shift-JIS | Detected by scoring, at 85% or less. The entry reads Windows code page 932. | Listed. There is no separate CP932 or Windows-31J entry. |
| EUC-JP | Detected by scoring, at 85% or less. The entry reads the two-byte characters and half-width katakana. The three-byte characters and the Windows vendor characters that some EUC-JP files carry are not read correctly, and a file that holds them may not be detected as EUC-JP. | Listed. |
| ISO-2022-JP | Not detected. The file opens as UTF-8, and the Japanese shows as ASCII letters and symbols between escape characters. | Not listed. Convert the file with iconv first. |
| GB18030, Big5 and EUC-KR | Detected by scoring, at 85% or less. | Listed. |
| Windows-1252, Windows-1251, KOI8-R, ISO-8859-5, Windows-1250 and ISO-8859-2 | Detected by scoring, at 85% or less. | Listed. |
| ISO-8859-1 | Scored beside Windows-1252, which reads the same letters and is preferred, so Western European text opens as Windows-1252. | Listed. |
| Windows-1254 and Windows-1257 | Never detected. | Listed, for Turkish and Baltic text. |
| UTF-8 and UTF-8 (BOM) | Detected when every byte is valid UTF-8, or from the mark EF BB BF. A file whose first 256 KB hold at most 12 invalid sequences, and at least 16 valid multi-byte characters for each one, is still read as UTF-8, at 89%. | Listed. |
Three rules decide the confidence you see. A byte order mark settles the encoding at 100%. Unmarked UTF-16 gets between 85% and 95% when its zero bytes give it away, more when more of the text is ASCII, and 85% when it is found by reading the bytes in pairs, or 75% when a damaged pair was passed over. An encoding found by scoring gets 85% at most. It gets ten points less when a second encoding fits almost as well, in which case the Inspector's sentence ends with the words fits almost as well, and ten points less when it was read around damaged bytes. Below 90% the Detected banner appears and stays. Open a GB18030, GBK, or Big5 file on a Mac covers the Chinese encodings.
What does Shift-JIS mean in Caxton?
Caxton has one Shift-JIS entry, and it reads the Windows table, code page 932. The NEC and IBM extension characters are read as themselves, so 髙, ㈱ and ① in the customer list appear correctly, and that file is detected on open the same way as the plain Shift-JIS minutes. The byte 5C is read as a backslash, as on Windows, so the path C:\data\list.txt keeps its backslashes. Saving follows the same table in the other direction. The yen sign as a character of its own, U+00A5, has no byte in that table, so a document that holds one cannot be saved as Shift-JIS, and the save stops with Can't save in Shift-JIS. There is no entry for a strict reading of the standard, for Shift_JIS-2004 or for the old Mac Japanese encoding.
Can Caxton open a large UTF-16 file, or a UTF-16 CSV?
Yes to both, and the working copy is the reason. Caxton's text view, search and table all work on UTF-8, so a file in UTF-16, Shift-JIS or any other encoding that is not UTF-8 is converted into a UTF-8 working copy as it opens. The conversion runs in the background with progress and a cancel, and it only reads your file. In the Inspector, the File section shows the size of the working copy under the size of the file.
- A large file. A file of 300 MB or more goes through the Open Large File dialog. If you choose Windowed Slice or Tail there, Caxton converts only that part of the file, starting at the beginning of a line. Three commands change the file as a whole and are not available in such a window: File ▸ Save with Encoding…, Text ▸ Byte Order Mark and Text ▸ Line Endings. Open the file whole to use them. The filter bar's Entire File checkbox is also unavailable there for a file that is not UTF-8.
- A CSV or TSV. A .csv or .tsv file opens as a table whatever its encoding, because the table is built on the working copy. A tab-delimited .txt file of ten lines or more opens as a table too. View ▸ CSV Grid View, or ⇧⌘C, switches between the table and the text. Viewing, searching and filtering the table are Caxton Free at any size, and editing in the table is Caxton Pro.
Which way of opening fits which job?
| The job | Tools included with macOS | In Caxton |
|---|---|---|
| You only need to read a short file. | TextEdit opens it once you choose the encoding under Show Options in the Open dialog. | The file opens with its encoding detected and named in a banner. |
| You do not know what the file is. | file -I names UTF-16 when the file has a mark, and xxd shows the bytes. | The Inspector gives the evidence for the encoding Caxton chose, and Reopen with Encoding tries another without changing the file. |
| Another program needs the file as UTF-8. | iconv writes a UTF-8 copy in one command when you give it the right name. | File ▸ Save As… writes a UTF-8 copy, and File ▸ Save with Encoding… converts the file itself. |
| The file has to go back to a Windows system in its own encoding. | Convert to UTF-8, edit, and convert back with iconv, naming CP932 both times. | ⌘S writes the file back in the encoding it opened in. |
| The file is ISO-2022-JP, or UTF-32 without a mark. | iconv converts both to UTF-8. | Caxton reads neither. Convert the file first. |
| The same conversion runs on many files or on a schedule. | A loop around iconv is the better tool here. | Caxton works on the file in front of you, and a file pattern rule sets the encoding for files that arrive under the same name. |
Open the file, read the banner, and choose File ▸ Reopen with Encoding if the text is wrong. Nothing on disk changes until you save.
Download Caxton for Free7-day free trial of Caxton Pro, every feature, no credit card required. After it, Caxton Free keeps opening, searching and filtering at any size, and you can edit and save files up to 10 MB as text.
Frequently asked questions
How do I open a UTF-16 or Shift-JIS file on a Mac?
To open a UTF-16 or Shift-JIS file on a Mac, tell the program which encoding the file is in, because the bytes are intact and only the reading is wrong. In TextEdit, choose File, then Open, select the file, click Show Options and pick the encoding from the Plain Text Encoding menu, or write a UTF-8 copy in Terminal with a command such as iconv -f CP932 -t UTF-8 customers-cp932.csv > customers-utf8.csv, where UTF-16 takes the place of CP932 for a UTF-16 file that starts with a byte order mark. Caxton, a native Mac editor for text and data files, detects UTF-16 and Shift-JIS as the file opens and names the encoding in a banner, and when the text is still wrong you choose File ▸ Reopen with Encoding ▸ UTF-16 LE, UTF-16 BE or Shift-JIS, which reads the same bytes again and changes nothing on disk.
Why is Japanese text garbled when I open a file on my Mac?
The file is probably in Shift-JIS, the Japanese encoding that Windows writes, and the program read its bytes as UTF-8 or as a Western encoding. Read as Windows-1252, the Shift-JIS bytes for 日本語 show as “ú–{Œê. Nothing is damaged, and the text returns when the file is opened with the right encoding. In TextEdit, click Show Options in the Open dialog and choose the encoding. In Terminal, iconv -f CP932 -t UTF-8 writes a readable copy. In Caxton, a Shift-JIS file is detected as it opens, and File ▸ Reopen with Encoding ▸ Shift-JIS or EUC-JP reads the file again when the detection is wrong.
What is the difference between Shift-JIS and CP932?
CP932 is the Shift-JIS that Windows writes. Its registration with IANA, under the name Windows-31J, describes it as a variant of Shift_JIS that includes NEC special characters and IBM extensions, and notes that such text is commonly declared with the shift_jis name. Characters such as ①, ㈱ and 髙 exist only in the Windows variant. In the tests for this guide, iconv -f SHIFT_JIS stopped with Illegal byte sequence at the first of them, and iconv -f CP932 converted the whole file. The two names also disagree about the byte 5C, which iconv reads as a yen sign under SHIFT_JIS and as a backslash under CP932. Caxton has one entry, named Shift-JIS, and it reads code page 932.
How do I open a UTF-16 file that has no byte order mark?
Name the byte order yourself, because nothing at the start of the file gives it. Windows tools write little-endian UTF-16, so in Terminal try iconv -f UTF-16LE -t UTF-8 first, and UTF-16BE if the result is unreadable. The plain name UTF-16 assumes big-endian for a file without a mark, and in a test for this guide it wrote unrelated characters with no error. Caxton recognizes unmarked UTF-16 by the zero byte beside each ASCII character, so a log or a CSV that is mostly ASCII opens correctly. It recognizes text that is mostly Japanese, Chinese or Korean by reading the bytes in pairs in both byte orders. Unmarked UTF-16 that is mostly in another script, such as Cyrillic, Greek or Thai, is not recognized, and a very short file may not be. For such a file, choose File ▸ Reopen with Encoding ▸ UTF-16 LE.
Does Caxton open ISO-2022-JP or UTF-32 files?
Caxton reads a UTF-32 file that starts with its byte order mark. It does not read UTF-32 without a mark, and it does not read ISO-2022-JP. Neither is in the Reopen with Encoding menu, and an ISO-2022-JP file opens as UTF-8 with its Japanese showing as ASCII letters and symbols. Convert such a file first with iconv, which is included with macOS and has the names ISO-2022-JP, UTF-32LE and UTF-32BE, and open the UTF-8 result.
Sources
- Caxton manual: Encodings, with detection, Reopen with Encoding and Save with Encoding
- Caxton manual: the Inspector
- Caxton manual: opening large files and the Open Large File dialog
- IANA: the registration of the Windows-31J charset
- Microsoft Learn: Code Page Identifiers
- Microsoft Learn: about_Character_Encoding for Windows PowerShell 5.1
- Unicode Consortium: UTF-8, UTF-16, UTF-32 and BOM FAQ
- Apple Support: If characters aren't displayed correctly in TextEdit on Mac
- Apple's manual pages on macOS:
man file,man iconvandman xxd, read with the shipped tools in Terminal, and the list printed byiconv -l