Reading lines from text file and null point exception <pre><code>for(File d : documents) { if(d.isFile()) count++; { BufferedReader inputStream = null; try { inputStream = new BufferedReader(new FileReader(d)); String line; while ((line = inputStream.readLine()) !=null) { //condition to check the hyphen at end of line if(line.charAt(line.length() -1) == 45) { line = line.replace(line.charAt(line.length() -1),' '); String line2 = inputStream.readLine(); line = line.trim()+line2; } System.out.println(line); } finally { try { if(inputStream != null) inputStream.close(); } catch(IOException e) { } } } // System.out.println("\n" + tokens1); //System.out.println("\n" + count); } } catch(Exception e) { System.out.println("Null point exception"); } </code></pre> <p>When I remove the <strong>condition to check hyphen</strong>, it reads all the lines in the files and displays null pointer exception at the end. When I include this condition, it reads the file but whenever it finds first empty line, it stops and throws a null pointer exception.</p>