'Not able to read a file from other package in the same module

I am using Intellij Idea - 2021.2.4 and Java 8. In Intellij, I am not able to read a file in another package in the same module. The file is under main and not resource folder. 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!!");
        }
    }
}

enter image description here

In Intellij, the code prints "Resource is null", but in eclipse, the code prints "Resource found!!".

Is there any setting I need to enable/disable in intellij ? Why code is behaving different in Intellij Idea ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source