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");
}
When I remove the condition to check hyphen, 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.