title: Reading files with JFileChooser
body: <p>I always get a NullPointerException with this code</p>
  
  <pre><code>open.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
          modify = true;
          JFileChooser chooser = new JFileChooser();
          file = chooser.getSelectedFile();
          BufferedReader reader;
          StringBuilder sb = new StringBuilder();
          try {
              reader = new BufferedReader(new FileReader(file));
              String line = reader.readLine();
              while(line != null) {
                  sb.append(line);
                  sb.append(System.lineSeparator());
                  line = reader.readLine();
              }
              text.setText(sb.toString());
          } 
          catch (FileNotFoundException e1) {
              e1.printStackTrace();
          }
          catch (IOException e1) {
              e1.printStackTrace();
          }
      }
  });
  </code></pre>
  
  <p>NullPointerException on the line <code>reader = new BufferedReader(new FileReader(file));</code></p>
  
  <p>How can I reorganize my code?</p>