title: Java: No Such File Or Directory (Using Scanner Class)
body: <p>I'm trying to read from a file using the Scanner and File class: </p>
  
  <pre><code>import java.util.Scanner;
  import java.io.File;
  import java.io.IOException;
  public class TextFileReaderV1
  {
      public static void main(String[] args) throws IOException
      { 
  
          String token = "";
          File fileName = new File("data1.txt");
          Scanner inFile = new Scanner(fileName);
  
          while( inFile.hasNext() )
          {
              token = inFile.next( );  
              System.out.println(token); 
          }
          inFile.close();           
  
       }
  }
  </code></pre>
  
  <p>However, it is saying, "no such file or directory". and giving me the "java.io.FileNotFoundException"  </p>
  
  <p>I am using IntelliJ IDEA and the file is in the current directory I am working in: src/data1.txt -> next to GetFile.java (current code) </p>
  
  <p>Full Error Message:  </p>
  
  <pre><code> Exception in thread "main" java.io.FileNotFoundException: data1.txt (No such file or directory)  
  
    at java.io.FileInputStream.open0(Native Method)  
    at java.io.FileInputStream.open(FileInputStream.java:195)  
    at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:138)  
    at java.util.Scanner.&lt;init&gt;(Scanner.java:611)  
    at GetFile.main(GetFile.java:19)  
  </code></pre>
  
  <p>**Edit: ** It has been solved!! The run configuration was set to the project directory, not the src one, so I implicitly added it in the argument:</p>
  
  <pre><code>File fileName = new File("src/data1.txt");
  </code></pre>