title: Cannot read files from resources folder
body: <p><strong>Final edit:</strong> now the code looks like this</p>
  
  <pre><code>InputStream is = getClass().getResourceAsStream("/static/master-key.txt");
  String masterKey = null;
  Scanner scanner = new Scanner(is);
  masterKey = scanner.nextLine();
  System.out.println("the master key is " + masterKey);
  </code></pre>
  
  <p><strong>Original post</strong></p>
  
  <p>I have a problem when reading txt file from <code>resources</code> folder.</p>
  
  <p>This what project structure looks like:<br>
  <a href="https://i.stack.imgur.com/tVs2c.png" rel="nofollow noreferrer">projStructure</a></p>
  
  <p>When I invoke the following code</p>
  
  <pre><code>System.out.println(getClass().getClassLoader().getResource("static/master-key.txt").getPath());
  File mkFile = new File(getClass().getClassLoader().getResource("static/master-key.txt").getPath());
  </code></pre>
  
  <p>this what happens</p>
  
  <pre><code>/D:/Dropbox/Coding/Intellij%20IDEA/TishenkoKPO/target/classes/static/master-key.txt
  java.io.FileNotFoundException: 
  D:\Dropbox\Coding\Intellij%20IDEA\TishenkoKPO\target\classes\static\master-key.txt (System cannot find the specified path)
  </code></pre>
  
  <p>I've googled alot but have no clue of why this happens</p>
  
  <p><strong>Edit 1</strong>:
  Part of the code rebuilt as community suggested (working with file as a resource)</p>
  
  <pre><code>InputStream is = getClass().getResourceAsStream("static/master-key.txt");
  String masterKey = null;
  Scanner scanner = new Scanner(is);
  masterKey = scanner.nextLine();
  System.out.println("the master key is " + masterKey); //successfuly outputs the first line if exists 
  </code></pre>
  
  <p><strong>Edit 2:</strong> resourcepath should begin with <code>/</code></p>
  
  <pre><code>InputStream is = getClass().getResourceAsStream("/static/master-key.txt");
  </code></pre>