title: Processing a file with JFileChooser
body: <p>Hey guys I am running into an issue with my program. I am trying to get the program to only show text files, and once the user selects one, the file information should be displayed in a textbox in the GUI. I am getting this error:</p>
  
  <p><code>FileChooserDemo3.java:66: error: unreported exception IOException; must be caught or declared to be thrown
                   while ((strLine = br.readLine()) != null) {</code></p>
  
  <p>Why is this happening? I have a catch statement.. Thanks for any help!</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  import java.util.Scanner;
  import java.io.*;
  
  class FileChooserDemo3{
  
     JLabel jlab;
     JButton jbtnShow;
     JFileChooser jfc;
     JTextArea jta;
     JScrollPane scrollPane;
  
     FileChooserDemo3() {
        //create new JFrame container.
        JFrame jfrm = new JFrame("JFileChooser Demo");
  
        //Specify FlowLayout for layout manager
        jfrm.setLayout(new FlowLayout());
  
        //Give the frame initial size
        jfrm.setSize(800,800);
  
        //End program when user closes application
        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
        //Create a label to show selected file
        jlab=new JLabel();
  
        //Create button to show dialog
        jbtnShow = new JButton("Show File Chooser");
  
        //create textarea with ability to textwrap (p889-891) and scroll (hint:  Use JScrollPane)
        JTextArea textInput = new JTextArea(20, 40);
        textInput.setLineWrap(true);
        JScrollPane scrollPane = new JScrollPane(textInput);
  
  
  
  
        //Create file chooser starting at default directory
        jfc=new JFileChooser();
  
        //Show file chooser when show file chooser button pressed
        jbtnShow.addActionListener(new ActionListener()  {
           public void actionPerformed(ActionEvent le) {
              //Pass null for the parent.  This centers the dialog on the screen.
              int result = jfc.showOpenDialog(null);
  
              if(result==JFileChooser.APPROVE_OPTION){
                 jlab.setText("Selected file is:  " + jfc.getSelectedFile().getName());
  
                 //Get selected file stored as a file.
  
  
  
  
                 try{
                    //Do file processing here
                   String strLine;
                   File selectedFile = jfc.getSelectedFile();
                   FileInputStream in = new FileInputStream(selectedFile);
                   BufferedReader br = new BufferedReader(new InputStreamReader(in));
                   while ((strLine = br.readLine()) != null) {
                       textInput.append(strLine + "\n");
                   }
                 }
  
                 catch(FileNotFoundException e){
                    System.out.println("Exception");
                 }
  
  
  
              }
              else{
                 jlab.setText("No file selected.");
              }
           }
        });
  
           //add the show file chooser button and label to content pane
           jfrm.add(jbtnShow);
           jfrm.add(jlab);
  
  
           //Display the frame
           jfrm.setVisible(true);
     }
  
     public static void main(String[] args){
        //Create GUI on the event dispatching thread.
        SwingUtilities.invokeLater(new Runnable() {
           public void run() {
              new FileChooserDemo3();
           }
        });
     }
  }
  </code></pre>