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.
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
When the “Invalid character detected” dialog box pops up, click the 「Change Encoding (E)…」 button inside it.
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.
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:
Click Save As in the editor’s menu bar.
In the save dialog, find Display Options – Encoding, and change it from “Auto Detect” to UTF-8.
Keep the file name and path unchanged (to overwrite the original file), and click Replace.
Close the document, then reopen it.
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:
Change the encoding to GBK → Make the document display normally.
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.