After switching from Windows to Ubuntu, the prompt ‘Invalid characters detected’ pops up when opening the document I wrote before, and the content is displayed as garbled characters. Here is a record of the effective solution I personally tested, the whole process only needs the mouse to operate.
1. Problems
In the Ubuntu 26.04 system, use the text editor that comes with the system (the Gnome default editor) to open one before Windows 10 .txt When documenting, an error message pops up:
Invalid character detected An encoding conversion error has occurred so a fallback character is used.
The document content is displayed as a bunch of similar D6C0E0CFC2B5C4... garbled, unreadable.
The reason for the analysis
This problem is usually because the text encoding used by Windows and Linux is different by default.
Windows 10 (Simplified Chinese version) is used by default GBK(or GB18030) encoding to save the text file.
Ubuntu is used by default UTF-8 code.
When the text editor of Ubuntu automatically detects the encoding, it mistakes the GBK file to be opened as a UTF-8, and the error of ‘invalid character’ is reported when it encounters an unrecognized byte.
3. Solution steps (full mouse operation)
The following is the process of my actual operation.
Step 1: Manually change the code to GBK
When the ‘Invalid Character Detected’ dialog box pops up, click the ‘Change Code (E)…’ button.
In the ‘Change Code’ window that pops up, the default is selected UTF-8. Find and select from the list Simplified Chinese (GBK)(You can also choose GB18030 or GB2312).
I chose GBK.
At this time, the editor will use the GBK encoding to reload the document, the content will be restored to normal, and both Chinese and English can be displayed correctly.
Step 2: Save the document as UTF-8 (override the original file)
Although the document is already readable, it is essentially GBK encoding. In order to open it directly in any Linux environment in the future, it can be converted into UTF-8 encoding common to Ubuntu.
The operation is as follows:
Click on the editor menu bar Save as.
Find Options in the Save dialog box – Coding , change it from ‘Auto Detect’ to UTF-8.
Keep the file name and path unchanged (override the original file), click Replace.
Close the document and reopen it.
After reopening, no error message will appear, and the content is displayed perfectly. This file can also be opened in most modern editors (including new versions of Notepad under Windows) in the future.
4. How to avoid encountering similar problems again in the future
If you often need to open a text file copied from Windows in Ubuntu, you can try the following habits.
Save it directly as UTF-8 when creating a file under Windows (most of my files are UTF-8)
Use the built-in Windows Notebook: After editing, click ‘File’ → ‘Save As’, and select in the ‘Encoding’ drop-down box UTF-8.
Use notepad++: After opening the file, click the menu ‘Encoding’ → ‘Convert to UTF-8 without BOM encoding’. The files saved in this way are better compatible under Ubuntu.
5. Summary
When encountering an ‘invalid character’ error, it only takes two steps to solve it:
Change the code to GBK → Let the document display normally.
Save as UTF-8 → Permanently solve the coding problem.
The whole process does not need to use the command line, it can be completed with a few clicks in the graphical interface. I hope this record can be helpful to friends who encounter a similar situation.