没有不值得去解决的问题,也没有不值得去学习的技术!

Fixing the “Invalid Character” Error When Opening Windows Documents on Ubuntu

In the save dialog, find Display Options - Encoding, and change it from "Auto Detect" to UTF-8.

After switching from Windows to Ubuntu, an “Invalid character detected” prompt popped up when I opened a previously written document, and the content displayed as garbled text. Here is a solution I personally tested and found effective; the entire process requires only a mouse.

1. Symptoms

In Ubuntu 26.04, when I used the built-in text editor (the default GNOME editor) to open a .txt document previously written on Windows 10, an error prompt appeared:

Invalid character detected
An encoding conversion error occurred, so a fallback character was used.

Invalid character detected An encoding conversion error occurred, so a fallback character was used.

The document content displayed as a bunch of garbled text similar to D6C0E0CFC2B5C4..., making it unreadable.

2. Brief Cause Analysis

This problem usually occurs because Windows and Linux use different default text encodings.

  • Windows 10 (Simplified Chinese version) saves text files using the GBK (or GB18030) encoding by default.
  • Ubuntu uses the UTF-8 encoding by default.

When Ubuntu’s text editor automatically detects the encoding, it mistakenly opens the GBK file as UTF-8. Upon encountering unrecognizable bytes, it throws the “invalid character” error.

3. Solution Steps (Mouse Only)

The following is the actual process I performed.

Step 1: Manually change the encoding to GBK

  1. When the “Invalid character detected” dialog box pops up, click the 「Change Encoding (E)…」 button inside it.
  2. In the “Change Encoding” window that appears, UTF-8 is selected by default.
    Find and select Simplified Chinese (GBK) from the list (you can also choose GB18030 or GB2312).

I chose GBK.

The editor will then reload the document using GBK encoding. The content will return to normal, and both Chinese and English will display correctly.

The editor will then reload the document using GBK encoding. The content will return to normal, and both Chinese and English will display correctly.

Step 2: Save the document as UTF-8 (overwrite the original file)

Although the document is now readable, it is still essentially GBK encoded. To ensure it can be opened directly in any Linux environment in the future, you can convert it to UTF-8, which is standard for Ubuntu.

Proceed as follows:

  1. Click Save As in the editor’s menu bar.
  2. In the save dialog, find Display Options – Encoding, and change it from “Auto Detect” to UTF-8.
  3. Keep the file name and path unchanged (to overwrite the original file), and click Replace.
  4. Close the document, then reopen it.
In the save dialog, find Display Options - Encoding, and change it from "Auto Detect" to UTF-8.

Upon reopening, the error prompt no longer appears, and the content displays perfectly. This file can also be opened normally in most modern editors (including the new version of Notepad on Windows) in the future.

4. How to Avoid Similar Issues in the Future

If you frequently need to open text files copied from Windows in Ubuntu, you can try adopting the following habits.

Save files directly as UTF-8 when creating them on Windows (most of my files are UTF-8)

  • Using the built-in Windows Notepad: After editing, click “File” → “Save As”, and select UTF-8 from the “Encoding” drop-down menu.
  • Using Notepad++: After opening the file, click the “Encoding” menu → “Convert to UTF-8 without BOM”. Files saved this way have better compatibility on Ubuntu.

5. Summary

When you encounter the “invalid character” error, you can solve it in just two steps:

  1. Change the encoding to GBK → Make the document display normally.
  2. Save as UTF-8 → Permanently resolve the encoding issue.

The entire process requires no command line; you can complete it with a few mouse clicks in the graphical interface. I hope this record helps anyone encountering a similar situation.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系