The Scenario
Imagine opening a 10-year-old SQL dump or a CSV export from an old version of Excel. Instead of clean code, you are greeted by a wall of `` symbols or weird character strings like é. Sometimes, VS Code won't even try to render the text. It simply shows a notification bar claiming the file is binary.
File seems to be binary or uses an unsupported text encoding. Please open it with the 'reopen with encoding' command.
The root cause is a simple misunderstanding. VS Code expects UTF-8, which is the standard for over 95% of the web. However, your file might be using Windows-1252, Shift-JIS, or UTF-16. When the editor fails to map those raw bytes to UTF-8, it assumes you’re trying to read an image or a PDF and stops trying.
Quick Fix: Reopen with the Correct Encoding
Need to read the file immediately? You can manually tell VS Code which "dictionary" to use to translate those bytes. Follow these steps:
- Check the Status Bar at the bottom right of your window. Look for the text that says "UTF-8" or "Binary."
- Click that text to trigger the command palette.
- Select "Reopen with Encoding" from the dropdown.
- VS Code will list several options. If you are dealing with an old Windows file, Windows-1252 usually works. For files from East Asian systems, try Shift-JIS or EUC-JP.
- The text should instantly become readable. If it still looks like gibberish, repeat the process and choose "Guess from content."
Permanent Fix: Converting the File to UTF-8
Opening the file is only half the battle. To prevent this error from haunting your teammates, convert the file to UTF-8 permanently. This is the industry standard for modern version control systems like Git.
- Locate the encoding name in the Status Bar again (it should now show the one you just picked, such as "Windows-1252").
- Click it and select "Save with Encoding" this time.
- Choose UTF-8 from the list.
- Hit
Ctrl + S(orCmd + Son Mac) to commit the change.
Your file is now modernized. Future developers won't need to guess the encoding when they pull your code.
Automating Encoding Detection
Manually switching encodings is tedious if you handle legacy data daily. You can force VS Code to do the heavy lifting by enabling the auto-guess feature. It analyzes byte patterns to pick the most likely charset.
- Press
Ctrl + ,(orCmd + ,) to open Settings. - Search for
files.autoGuessEncoding. - Check the box to enable it.
Keep in mind that this adds a tiny bit of overhead when opening massive files. For most users, the convenience outweighs the millisecond of lag.
Dealing with Encoded Strings
Sometimes the file itself is UTF-8, but the content is intentionally obscured. This is common in API logs or JSON files containing Base64 data. If you see a string like SGVsbG8gV29ybGQ=, changing the file encoding won't help.
In these cases, I use ToolCraft's Base64 Decoder. It lets you quickly decode strings to see the underlying data. It is a safer bet than random online converters because it handles sensitive strings without server-side logging.
Verification: How to Confirm the Fix
Don't assume it's fixed just because it looks okay on your screen. Run these quick checks:
- Status Bar Check: Ensure it explicitly displays "UTF-8."
- The Reload Test: Close the tab and reopen it. It should open instantly without the "binary" warning.
- Git Diff: Run
git diffin your terminal. You should see the garbled characters replaced by the correct ones. Be aware that a full encoding change might mark every line in the file as "modified."
Common Encodings at a Glance
Source Material
Likely Encoding
Legacy Windows/Excel CSVs
Windows-1252
Old Linux/Unix Text Files
ISO-8859-1
Japanese Legacy Systems
Shift-JIS
Standard Modern Code
UTF-8

