Android Studio shows wrong file contents

I have an odd problem with Android Studio. Here is how my class file looks like on Android Studio

And here is what it looks like on a text editor.

enter image description here

Any ideas why it is happening? I have tried closing then reimporting the project, invalidate caches and restart, clean project, build project, delete .idea folder and .iml files. All of my files are broken when opening in AS but looks fine on text editors.


UPDATE: Quicker solution by the user Hong given below:

Delete the caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches

=====================

Here's what worked for me.

  1. Close Android Studio
  2. Go to C:\Users*your username*
  3. Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
  4. Rename it to something like old.AndroidStudioX.X
  5. Start Android Studio, and when it asks if you want to import settings, choose the old directory

This should fix the issue.


Thanks to the Answer of Asim, I found deleting folder caches fixed the problem for my case (all gradle files in Android Studio show contents that have nothing to do with the actual contents of these files):

C:\Users\my_user_name\.AndroidStudio3.3\system\caches

Edit[2020-07-17]:

This is still happening with Android Studio 4.0, so I have to delete the following folder to fix this problem:

   C:\Users\my_user_name\.AndroidStudio4.0\system\caches

Edit[2021-11-08]: This solution no longer works for Android Studio Arctic Fox. Please see the new answer by Nikunj Paradva. I have used the new solution and it works.


Solution for Android studio Arctic Fox and Higher Versions

Steps

  • Exit Android Studio

  • Delete caches folder from

    C:\Users\{username}\AppData\Local\Google\AndroidStudio2020.3 // For Arctic Fox 
    
  • Open Android Studio and your code has being Perfect

Check your Android studio version and Target that version folder at below location

C:\Users\{username}\AppData\Local\Google

Note : AppData folder is Hidden in Windows


Does this situation warrant a bug report?

Yes! In fact this problem has been reported to the Android Studio team, and anyone willing to help us investigate is welcome to contribute there. Thanks!

You can also try the workaround in Hong's answer.