keepcalculator

06 Numbers and Powers

Repair Corrupted TXT Files: 6 Fixes That Work

Card No. 06·6772 · Updated · Standard formula, shown below

If a .txt file opens as garbled characters, shows an encoding error, or won’t open at all, you can usually repair it yourself with built-in tools or free software. This article explains the common causes of TXT corruption and gives you six practical methods to recover your text, from simple encoding changes to hex editing.

Why TXT Files Get Corrupted

Plain text files are simple, but they still get corrupted. The most frequent causes are:

  • Interrupted writes – power loss or a crash while saving can leave a file half-written.
  • Encoding mismatches – a file saved as UTF-8 opened as Windows-1252 (or vice versa) shows mojibake like “ instead of quotes.
  • Bad sectors – on a failing hard drive or USB stick, parts of the file may be unreadable.
  • Software bugs – some editors, especially older ones, may mishandle large files or special characters.
  • Incorrect file extension – a binary file renamed to .txt will appear as random symbols.

Method 1: Open with a Different Text Editor

Before trying anything complex, open the file in a different editor. Notepad on Windows, TextEdit on macOS, and VS Code or Notepad++ on any platform all handle encoding differently. A file that looks broken in Notepad may open fine in VS Code because VS Code auto-detects encoding better. If the file opens correctly in one editor, simply re-save it as UTF-8 with the correct line endings.

Method 2: Change the File Encoding

If you see replacement characters (�) or odd letters, the file is probably fine but the encoding is wrong. Here’s how to fix it in Notepad++ (free):

  1. Open Notepad++ and go to Encoding menu.
  2. Try Encode in UTF-8 or Encode in ANSI – watch the text change.
  3. Once the text looks correct, go to Encoding → Convert to UTF-8 and save.

In VS Code, click the encoding label in the bottom-right corner (e.g., “UTF-8�) and choose Reopen with Encoding. Try UTF-8, Windows-1252, or ISO-8859-1. When the text displays correctly, save with the desired encoding.

Method 3: Use a File Repair Tool

For files that are partially overwritten or have a damaged header, dedicated tools can help. Free options include:

  • File Repair (Windows) – scans for readable text and rebuilds a new file.
  • Recover My Files (trial) – can recover deleted or corrupted text files from drives.
  • TextRecover (online) – extracts readable text from a corrupted file by ignoring binary junk.

These tools work by scanning the file byte-by-byte and keeping printable characters. They won’t restore the original structure, but they can save the content.

Method 4: Extract Text with a Hex Editor

If the file is severely damaged, a hex editor (like HxD for Windows or Hex Fiend for macOS) lets you see the raw bytes. You can often spot the text among the garbage. Steps:

  1. Open the file in the hex editor.
  2. Look for long runs of ASCII characters (hex values 20–7E).
  3. Copy the readable parts manually and paste into a new text file.

This is tedious but works when only a few sections are corrupted.

Method 5: Recover from Backup or Shadow Copy

If you have File History (Windows) or Time Machine (macOS) enabled, you can restore a previous version. On Windows, right-click the file → Properties → Previous Versions tab. On macOS, enter Time Machine and navigate to the file’s location. If you use cloud storage (Google Drive, Dropbox, OneDrive), check the version history in the web interface – they often keep older copies for 30 days.

Method 6: Use Command-Line Tools (Linux/macOS)

On Unix-like systems, you can use strings to extract printable text:

strings corrupted.txt > recovered.txt

This command prints sequences of printable characters (default length 4 or more) to a new file. It won’t preserve formatting, but it will capture all readable text. For more control, use grep -a to search for specific terms.

How to Prevent Future Corruption

Once you recover your file, take these steps to avoid a repeat:

  • Always close files properly – don’t yank out USB drives while writing.
  • Enable versioning in your editor (e.g., VS Code’s local history).
  • Save important text as UTF-8 with BOM to reduce encoding ambiguity.
  • Back up regularly to an external drive or cloud service.

Frequently Asked Questions

Can I repair a TXT file that is completely empty?

If the file is 0 bytes, the data is likely gone. Check for backups or use file recovery software that scans the disk for deleted file fragments – but success depends on whether the disk space has been overwritten.

Why does my TXT file show random symbols like ?

That’s a UTF-8 byte order mark (BOM) being displayed as text. It usually appears when a file saved with a BOM is opened in an editor that doesn’t recognize it. Open in a proper editor and re-save without BOM, or use a hex editor to delete the first three bytes (EF BB BF).

Is there a free online tool to repair TXT files?

Yes, several websites offer free text extraction from corrupted files. However, you should never upload sensitive data to an unknown service. For privacy, use offline tools like Notepad++ or a hex editor.

What’s the difference between a corrupted file and a wrong encoding?

A corrupted file has actual byte damage – missing or altered data. Wrong encoding means the bytes are intact but interpreted with the wrong character set. Wrong encoding is easily fixed; corruption requires recovery methods.

Can I repair a TXT file on my phone?

Yes, you can use apps like QuickEdit or Jota+ on Android, or Textastic on iOS, to open the file and try different encodings. For extraction, you might need a desktop computer.

Will these methods work for other text formats like .csv or .log?

Yes, the same principles apply to any plain-text-based file. CSV and log files are just text, so encoding fixes and text extraction work the same way.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →