title: Resolving IOException, FileNotFoundException when using FileReader
body: <p>I've not been able to resolve the following exception in the code below. What is the problem with the way I use  BufferedReader? I'm using BufferedReader inside the main method</p>
  
  <p>OUTPUT :-</p>
  
  <pre><code>ParseFileName.java:56: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown 
  
  BufferedReader buffread = new BufferedReader (new FileReader("file.txt"));
  </code></pre>
  
  <hr>
  
  <pre><code>// ParseFileName  is used to get the file name from a file path 
  // For eg: get  - crc.v  from "$ROOT/rtl/..path/crc.v"
  
  import java.util.regex.Pattern;
  import java.io.*;
  
  public class ParseFileName { 
  
    //Split along /'s , and collect the last term. 
    public String getName (String longName) { 
        String splitAt = "/";
        Pattern pattern1 = Pattern.compile(splitAt);
        String[] parts  = pattern1.split(longName);
        System.out.println("\nparts.length =  " + parts.length);
  
        //Return the last element in the array of strings 
        return parts[parts.length -1]; 
    }
  
    public static void main(String[] args) { 
      ParseFileName  superParse = new ParseFileName();  
      BufferedReader buffread = new BufferedReader (new FileReader("file.txt"));
      String line;
      while ((line = buffread.readLine())!= null) {
          String fileName = superParse.getName(line);
          System.out.println("\n" + line + "  =&gt;  " + fileName);
      }
      buffread.close();
  
    }
  
  }
  </code></pre>
  
  <p><strong>UPDATE :</strong> 
  The following works:  </p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException, IOException { 
  </code></pre>
  
  <p>However try.. catch still has some nagging issues for me:  </p>
  
  <pre><code>try {
  BufferedReader buffread = new BufferedReader (new FileReader("file.txt"));
  } catch (FileNotFoundException ex) {
      ex.printStackTrace();
  } catch (IOException ex2) {
     ex2.printStackTrace();
  }
  </code></pre>
  
  <p>buffread dosent seem to get the file name. I get this error:</p>
  
  <pre><code>javac ParseFileName.java ParseFileName.java:67: cannot resolve symbol
  </code></pre>
  
  <p>symbol  : variable buffread  </p>
  
  <pre><code>location: class ParseFileName
  
  while ((line = buffread.readLine())!= null) {
  </code></pre>