maven: java.io.FileNotFoundException when trying to open file from resources with Intellij or using java command with jar
<p>I've imported the <a href="https://github.com/java8/Java8InAction" rel="nofollow noreferrer">github's</a> project from the book "Java 8 In Action" in intellij as a maven project. </p>

<p>The module structure is the following:</p>

<p><a href="https://i.stack.imgur.com/5vC0i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5vC0i.png" alt="enter image description here"></a></p>

<p>Then, i'm executing the Main method from the ExecuteAround class directly from Intellij (right click -> execute main...)</p>

<pre><code>public static void main(String ...args) throws IOException{

    // method we want to refactor to make more flexible
    String result = processFileLimited();
    System.out.println(result);

    System.out.println("---");

    String oneLine = processFile((BufferedReader b) -&gt; b.readLine());
    System.out.println(oneLine);

    String twoLines = processFile((BufferedReader b) -&gt; b.readLine() + b.readLine());
    System.out.println(twoLines);

}

public static String processFileLimited() throws IOException {
    try (BufferedReader br =
                 new BufferedReader(new FileReader("lambdasinaction/chap3/data.txt"))) {
        return br.readLine();
    }
}


public static String processFile(BufferedReaderProcessor p) throws IOException {
    try(BufferedReader br = new BufferedReader(new FileReader("lambdasinaction/chap3/data.txt"))){
        return p.process(br);
    }

}

public interface BufferedReaderProcessor{
    public String process(BufferedReader b) throws IOException;

}
</code></pre>

<p>And then, i'm getting a FileNotFoundException:</p>

<pre><code>Exception in thread "main" java.io.FileNotFoundException: lambdasinaction\chap3\data.txt
</code></pre>

<p>If a execute a "maven package", in the jar, the data.txt file is directly included in the chap3 folder/package but i get the same error if I execute:</p>

<pre><code>java -classpath lambdasinaction-1.0.jar lambdasinaction.chap3.executeAround
Exception in thread "main" java.io.FileNotFoundException: lambdasinaction\chap3\data.txt (Le chemin d?accès spécifié est introuvable)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(Unknown Source)
        at java.io.FileInputStream.&lt;init&gt;(Unknown Source)
        at java.io.FileInputStream.&lt;init&gt;(Unknown Source)
        at java.io.FileReader.&lt;init&gt;(Unknown Source)
        at lambdasinaction.chap3.ExecuteAround.processFileLimited(ExecuteAround.java:23)
        at lambdasinaction.chap3.ExecuteAround.main(ExecuteAround.java:9)
</code></pre>

<p>1- Why is it not running directly from intellij?  The file is correctly in the resource folder.</p>

<p>2 - This is probably most important: Why is it not running when executing the programm directly from the command line?</p>

<p>Thanks for the help</p>