title: Read file name from user input on linux terminal - JAVA
body: <p>I want to make a little script in JAVA to receive a file name in the linux terminal and read that file.</p>
  
  <p>This is what i'm trying:</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  class ItauScript {
      public static void main(String[] args) {
          Scanner reader = new Scanner(System.in);
          System.out.println("Filename: ");
          String fileName = reader.next();
  
          FileReader fileReader = new FileReader(fileName);
          BufferedReader bufferedReader = new BufferedReader(fileReader);
  
          System.out.println(bufferedReader.readLine());
      }
  }
  </code></pre>
  
  <p>But the code doesn't compile. I get this error message:</p>
  
  <blockquote>
    <p>hello.java:10: error: unreported exception FileNotFoundException; must
    be caught or declared to be thrown
            FileReader fileReader = new FileReader(fileName);
                                    ^ hello.java:13: error: unreported exception IOException; must be caught or declared to be thrown
            System.out.println(bufferedReader.readLine());</p>
  </blockquote>
  
  <p>I can open the file if i put it on hardcode on a string.
  But i need to receive it as an input from the terminal.</p>
  
  <p>What am i missing?</p>