Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ not recognizing a particular file correctly, instead it's stuck as a text file

People also ask

How do I change file type in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | File Types. From the Recognized File Types list, select the file type that you want to associate with other filename patterns.

How do I fix read-only files in IntelliJ?

To toggle read-only attribute of a file, open file in the editor, or select it in the Project tool window. Do one of the following: On the main menu, choose File | File Properties | Make File Read-Only , or Make File Writable .

Why is a filename red in IntelliJ?

It means that the files exist locally, but are not in the repository, and are not scheduled for addition. With other words, the files are not under version control. There is not really a problem since the files can just be added to the VCS if desired.


Please ensure that this file (or a pattern that represents it) is not listed under

SettingsEditorFile TypesText

For OS X

PreferencesEditorFile TypesText

Sometimes the file or pattern are stuck under File type auto-detected by file content instead of Text.


Step 1: Click "File" ==> "Settings" for Windows or "InterlliJ IDEA" ==> "Preferences" for Mac

Step 2: Expand "Editor" & Click "File Types"

Step 3: You will see all file types on Right. Navigate to the "Text" entry and click it

Step 4: You should able to see your file name on the bottom of "Registered Patterns" (lower box)

Step 5: Remove your file from the "Registered Patterns". The problem should be solved and let you rename with fileName.java

Step 6: If not, delete the file from the project and create it again with name fileName

Source


In 2020 none of the posted answers worked, here's what did:

  1. Left click the file
  2. On the top toolbar, select File -> File Properties -> Associate with File Type

OSX:

Preferences > Editor > File Types > Text

Windows:

Settings > Editor > File Types > Text Files

I had the same problem and none of the above solution solved it. The thing that at the end solved it was by selecting the module and going to the module settings(press F4 on the module name)

Then in the Sources tab, select the "java" folder and press on the Sources button. That tells IntelliJ that the folder in question is a source code folder.

Then select the Test folder and press Tests.

That's it. Then it will recognize correctly the files and show errors as needed.

See below the screenshot.

enter image description here


I solved the same issue by

Right-click on the file ->  "Override File Type" -> Select the extension type the file has.