Your class is in package projectname, so the code is looking for the resource file projectname/config.properties, but the file is not there.

To look for resource file config.properties, use:

getClass().getResource("/config.properties");

as documented in the javadoc of getResource().

And remember, the resource may not be a file on the file system, so don't use e.g. File to access it. To read the content of the resource, use getResourceAsStream() instead.

Answer from Andreas on Stack Overflow
🌐
Mkyong
mkyong.com › home › java › java – read a file from resources folder
Java - Read a file from resources folder - Mkyong.com
September 4, 2020 - In Java, we can use getResourceAsStream or getResource to read a file or multiple files from a resources folder or root of the classpath.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 4408088791186-What-is-the-path-to-files-in-root-resources-folder
What is the path to files in root resources folder – IDEs Support (IntelliJ Platform) | JetBrains
October 12, 2021 - So I guess I'm not using the resources root correctly. Once I have a file in the resources root folder (or a folder inside of it) how do I get a path to that file? ... Once you have marked a folder as resource folder in IntelliJ, it is available in your code as via resource loader.
🌐
JetBrains
jetbrains.com › help › idea › resource-files.html
Resource files | IntelliJ IDEA Documentation
These files are located in the classpath of your application, and are usually loaded from the classpath using the following methods: ResourceBundle.getBundle() for properties files and resource bundles · getResourceAsStream() for icons and other files · For more information about these methods, refer to Location-Independent Access to Resources. When building an application, IntelliJ IDEA copies all resources into the output directory, preserving the directory structure of the resources relative to the source path.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360000093770-IntelliJ-not-finding-files-clearly-in-the-resources-folder
IntelliJ not finding files clearly in the resources folder. – IDEs Support (IntelliJ Platform) | JetBrains
March 1, 2018 - I'm working in IntelliJ, and I've created a 'resources' directory inside the module, and marked it as a 'Resources Root'. My issue now, is that it is not located in my 'src' folder, which shouldn't be a problem to begin with, however I'm having trouble getting the directory of the resources folder. After compiling into a JAR file, I assume all files from ...
🌐
Crunchify
crunchify.com › technology & tools › how to add resources folder, properties at runtime into intellij classpath? adding property files to classpath
How to add Resources Folder, Properties at Runtime into IntelliJ classpath? Adding Property files to Classpath • Crunchify
May 31, 2023 - Basically IntelliJ was giving me NullPointerException as it was not able to find resource folder at runtime. Here is a code block. String propFileName = "config.properties"; InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName); prop.load(inputStream); <========= NPE here while loading config.properties file if (inputStream == null) { throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath"); }
🌐
Bloomu
javabook.bloomu.edu › addresources.html
How to Add Resources to an IntelliJ Project
Next, you need to mark the folder as resources root. To do this, open the File > Project Structure dialog, select the Modules tab, and click on the resources folder. The result will be as shown below. Your application can now access resources from the resources folder.
Find elsewhere
🌐
Medium
medium.com › @rasheedamir › java-how-to-load-a-file-resources-folder-dcded6b5c089
Java — How to load a file from resources folder? | by Rasheed Amir | Medium
August 26, 2016 - Java — How to load a file from resources folder? Sometime during tests you may want to read a file from resources folder; and here is the java code which you can use to read the file: ClassLoader …
🌐
Coderanch
coderanch.com › t › 770883 › frameworks › Trouble-creating-viewing-files-resources
Trouble for creating/viewing files from the resources folder (intellij) (Spring forum at Coderanch)
March 7, 2023 - I check if the filename of the ... point, the file is not created. To somewhat work, i have to replace "uploadDir" to the absolute path : « C:/Users/blablabla/src/main/resources/static/img/articles/thumbnail/ ». Then the file is created....
🌐
How to do in Java
howtodoinjava.com › home › i/o › read a file from resources directory
Read a File from Resources Directory - HowToDoInJava
December 8, 2022 - When packaging the application as jar file, the file present in the '/resources' folder are copied into the root 'target/classes' folder. In this case, the file location is inside a zipped archive like jar-filename.jar/!filename.txt. We should directly read this file as InputStream.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 4417110777490-Intellij-Not-able-to-read-a-file-from-other-package-in-the-same-module
Intellij - Not able to read a file from other package in the same module – IDEs Support (IntelliJ Platform) | JetBrains
February 1, 2022 - But in Eclipse, I am able to read. For example. Below code prints different outputs in both eclipse and intellij. import java.net.URL; public class TestMain { public static void main(String[] args) { URL resource = TestMain.class.getResource("/org/files/input.txt"); if(resource == null) { System.out.println("Resource is null"); } else { System.out.println("Resource found!!"); } } }
🌐
Stack Overflow
stackoverflow.com › questions › 47275235 › how-do-you-properly-include-a-resource-folder-in-a-jar-artifact-in-intellij-idea › 47275495
java - How do you properly include a resource folder in a JAR artifact in IntelliJ IDEA? - Stack Overflow
November 13, 2017 - I have a project that reads graphics and sound effects from a folder labeled res. This folder is at the same directory level as the src folder. I have res marked as Resources Root. I configured my artifact to include res as a Content Directory by way of Project Structure -> Artifacts -> Add (Alt + Insert) -> JAR · Then, in the output layout tab, I pressed the Add dropdown box -> Directory Content -> res · When I run the project in Intellij, it finds the resources just fine.
🌐
YouTube
youtube.com › watch
How to create a Resource folder in Java with IntelliJ and how to access it - YouTube
I will be showcasing how to create a resource folder in Intellij, and I will create a method that readers a file form the resource folder and print the input...
Published   March 5, 2021
🌐
Java2Blog
java2blog.com › home › core java › java file io › read a file from resources folder in java
Read a file from resources folder in java - Java2Blog
January 12, 2021 - In this post, we will see how to read a file from resources folder in java. If you create a maven project(simple java or dynamic web project) , you will see folder src/java/resources.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 115000784590-Fetching-content-of-resource-folder-of-dependent-JAR-via-IntelliJ-plugin
Fetching content of resource folder of dependent JAR via IntelliJ plugin – IDEs Support (IntelliJ Platform) | JetBrains
December 20, 2017 - I need to provide a lookup feature, where users can find what files are present in resource folder of the dependent library "UserLookup" and also see their content. I have tried using below, however, this does not give any access to project dependencies. ProjectManager p = ProjectManager.getInstance(); Project[] projects = p.getOpenProjects(); FileEditorManager manager = FileEditorManager.getInstance(projects[0]); ... In order to get dependencies of you project you need to use com.intellij.openapi.roots.ModuleRootManager class.