Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Idea problem with text file impossible to read

I have a problem using Intellij Idea.

I am absolutely unable to load text file as InputStream - it doesnt matter where do I put the file (main/java, main/resources...) it just can't find the file - in Eclipse everything works just fine.

I tried setings->compiler->resource patterns and added ?*.txt but that doesn't seem to work either.

Any help is appreciated.

like image 428
Jarek Avatar asked Aug 18 '11 11:08

Jarek


People also ask

How do I change from read-only mode 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 file 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.


1 Answers

If you load it as a File, make sure that Working Directory is properly set in IDEA Run/Debug Configuration, since it's the default directory where Java will look for a file when you try to access it like new File("file.txt"). Working directory should be set to the directory of your project containing .txt files.

If you load files as a classpath resource, then they should reside somewhere under Source root and will be copied to the classpath according to Settings | Compiler | Resource Patterns.

If you can't get it working, upload your project somewhere including IDEA project files so that we can point to your mistake.

like image 84
CrazyCoder Avatar answered Sep 18 '22 15:09

CrazyCoder