title: File I/O error FileNotFoundException
body: <p>The following is the java code. I am trying to get the arrays from the problem1.txt and save it into the arraylist.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Scanner;
  
  class CSP {
      public int nMeetings;
      public static int nEmployees;
      public int nTimeSlots;
      public static int probNumber;
      public ArrayList&lt;ArrayList&lt;Integer&gt;&gt; nMeetingsPerEmployee;
      //public int[][] travelTime;
  
      public CSP(int nMeetings, int nEmployees, int nTimeSlots, int probNumber) throws FileNotFoundException {
          this.nMeetings = nMeetings; 
          this.nEmployees = nEmployees;
          this.nTimeSlots = nTimeSlots;
          this.probNumber = probNumber;
          this.nMeetingsPerEmployee = getnMeetingsPerEmployeeArrayList();
  
      }
  
      //gets nMeetingsPerEmployee Arrylist
      public static ArrayList&lt;ArrayList&lt;Integer&gt;&gt; getnMeetingsPerEmployeeArrayList() throws FileNotFoundException
      {
          ArrayList&lt;ArrayList&lt;Integer&gt;&gt; arraylist = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;();
  
          File openFile = null;
          if(probNumber == 1){
              openFile = new File("problem1.txt");
          }else if(probNumber == 2){
              openFile = new File("problem2.txt");
          }else if(probNumber ==3){
              openFile = new File("problem3.txt");
          }else
              System.out.println("File Not Found");
  
          Scanner in = new Scanner(openFile);
  
          for(int i=0; i&lt;5; i++)
              in.nextLine(); //skip 5 lines until matrix
  
          while(true){
              for(int i=0; i&lt;nEmployees; i++) //nEmployees = 33
              {
                  for(int j=0; j&lt;6 ;j++)
                  {
                      for(int k=0; k&lt;3; k++)
                          in.next(); //skip 3 characters until individual number
                      arraylist.get(nEmployees).set(nEmployees, Integer.parseInt(in.next()));
                      if(in.hasNext() == false);
                          break;
                  }
              }
  
          return arraylist;
          }
      }
  }
  
  public class CSP_Main
  {
      public static void main(String[] args) throws FileNotFoundException
      {
          CSP problem1 = new CSP(20, 33, 12, 1);
          //CSP problem2 = new CSP(20, 33, 12, 2);
          //CSP problem3 = new CSP(40, 62, 12, 3);
      }
  }
  </code></pre>
  
  <p>The following is the error I keep getting.</p>
  
  <pre><code>Exception in thread "main" java.io.FileNotFoundException: problem1.txt 
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:138)
      at java.util.Scanner.&lt;init&gt;(Scanner.java:611)
      at CSP.getnMeetingsPerEmployeeArrayList(CSP_Main.java:43)
      at CSP.&lt;init&gt;(CSP_Main.java:22)
      at CSP_Main.main(CSP_Main.java:70)
  </code></pre>
  
  <p>The following is the problem1.txt file that I am trying to read and save in the arraylist.</p>
  
  <pre><code>Number of meetings: 20
  Number of employees: 33
  Number of time slots: 12
  
  Meetings each employee must attend:
  1: 2   6   7   9  19
  2: 2   5   6  12  16
  3: 1   3   8   9  16
  4: 1   6  15  16  18
  5: 1   3   8  13  18
  6: 8  10  11  17  20
  7: 3   8  10  13  20
  8: 1   3  14  16  20
  9: 6   7   9  16  19
  10: 2   6   7  12  17  19
  11: 2   6   7   9  13
  12: 2   4   7  12  16
  13: 2   6   7   9  16  18
  14: 2   5  11  17  18
  15: 1   5  11  17  18  20
  16: 6   8  12  16  18
  17: 6   7  15  17  19
  18: 1   7  11  18  20
  19: 4   5   9  10  13
  20: 4   7   9  17  18
  21: 7  10  11  12  17
  22: 5   6   9  13  18
  23: 1   9  11  17  18
  24: 2  11  14  15  17
  25: 1   3  14  15  16
  26: 5   6  10  13  15
  27: 8  11  15  17  18
  28: 1   4   7   9  16
  29: 1  11  13  18  20
  30: 2   5  12  13  18
  31: 2   6   8  12  16
  32: 2   7  15  17  19
  33: 6   7  15  17  18
  
  Travel time between meetings: 
        1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
  1:    0  1  1  1  2  1  1  1  1  1  1  2  1  2  1  1  1  1  2  1
  2:    1  0  1  1  2  2  1  1  1  1  1  1  1  1  1  2  2  1  1  2
  3:    1  1  0  1  1  2  2  1  1  2  2  2  2  2  2  1  2  2  1  1
  4:    1  1  1  0  1  2  2  2  2  2  1  1  1  2  2  1  1  2  2  2
  5:    2  2  1  1  0  2  2  2  1  1  1  2  1  2  1  2  2  1  2  2
  6:    1  2  2  2  2  0  1  1  1  1  2  1  2  1  2  1  1  2  2  1
  7:    1  1  2  2  2  1  0  1  2  1  1  1  1  1  2  2  2  1  1  2
  8:    1  1  1  2  2  1  1  0  2  1  1  2  1  1  2  1  2  1  2  1
  9:    1  1  1  2  1  1  2  2  0  2  2  1  1  1  2  2  2  2  1  2
  10:   1  1  2  2  1  1  1  1  2  0  1  2  2  2  2  2  1  1  2  2
  11:   1  1  2  1  1  2  1  1  2  1  0  1  2  1  1  2  1  2  1  1
  12:   2  1  2  1  2  1  1  2  1  2  1  0  1  2  2  2  2  1  2  2
  13:   1  1  2  1  1  2  1  1  1  2  2  1  0  1  1  2  2  2  1  1
  14:   2  1  2  2  2  1  1  1  1  2  1  2  1  0  2  1  1  2  1  1
  15:   1  1  2  2  1  2  2  2  2  2  1  2  1  2  0  2  1  2  2  1
  16:   1  2  1  1  2  1  2  1  2  2  2  2  2  1  2  0  1  1  2  2
  17:   1  2  2  1  2  1  2  2  2  1  1  2  2  1  1  1  0  2  2  2
  18:   1  1  2  2  1  2  1  1  2  1  2  1  2  2  2  1  2  0  1  1
  19:   2  1  1  2  2  2  1  2  1  2  1  2  1  1  2  2  2  1  0  2
  20:   1  2  1  2  2  1  2  1  2  2  1  2  1  1  1  2  2  1  2  0
  </code></pre>
  
  <p>The problem1.txt file that I am trying to open is surely in the directory where my java codes are. So I don't know why I keep getting this error.</p>
  
  <p>Thank you for your time.</p>