title: How to read a file that is located in the project folder java
body: <p>Using eclipse, I have a file titled bad_words.txt in my project folder titled HackGSU. I want locate the file and read the contents of the file. I saw this answer <a href="https://stackoverflow.com/questions/19874066/how-to-read-text-file-relative-path">how to read text file relative path</a> and I tried this:</p>
  
  <pre><code>private static String words[][] = new String[3][];
  private static int ok = 17 + 2; //Add two for comment &amp; empty line in text file
  private static int med = 26 + 2; //Add two for comment &amp; empty line in text file
  private static int bad = 430 + 1; //Add one for comment in text file
  private static String p = new File("").getAbsolutePath();
  
  public static String[][] openFile() {
  
      p.concat("/HackGSU/bad_words.txt");
  
      //Set the a limit for the amount of words in each row
      words[0] = new String[getOk()];
      words[1] = new String[getMed()];
      words[2] = new String[getBad()];
  
      //Read the text file to add bad words to an array
      try {
          FileReader fr = new FileReader(p);
          //Wrap file
          BufferedReader br = new BufferedReader(fr);
  
          //Add each line of file into the words array
          for(int i = 0; i &lt; words.length; i++) {             
  
              for(int j = 0; j &lt; words[i].length; j++) {
                  try {
                      words[i][j] = br.readLine();
                  }
                  catch (IOException e) {
                      e.printStackTrace();
                  }
              }
          }
  
      }
      catch (FileNotFoundException e1) {
          e1.printStackTrace();
      }
  
      return words;
  }
  </code></pre>
  
  <p>But I received this traceback:</p>
  
  <pre><code>java.io.FileNotFoundException: C:\Users\nbrow_000\workspaceProjects\HackGSU (Access is denied)
  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 gsu.hack.harassment.BadWords.openFile(BadWords.java:28)
  at gsu.hack.harassment.HarassFilter.&lt;clinit&gt;(HarassFilter.java:10)
  at gsu.hack.harassment.CheckPercentage.main(CheckPercentage.java:20)
  
  Exception in thread "main" java.lang.NullPointerException
  at gsu.hack.harassment.HarassFilter.checkHarass(HarassFilter.java:23)
  at gsu.hack.harassment.CheckPercentage.main(CheckPercentage.java:20)
  </code></pre>
  
  <p>I also so this answer <a href="https://stackoverflow.com/questions/6259339/how-to-read-a-text-file-directly-from-internet-using-java">How to read a text file directly from Internet using Java?</a>, but I had a problem with the URL constructor.</p>
  
  <p>If I put the local file path (C://.../bad_words.txt) it works just fine, but how can I get the program to read the file so that if I package the software it will still find the proper file path.</p>