1

I am trying to read a line in a file and set a string equal to that and write it to a file FileOut.

I am currently reading all lines before this to get to the line needed as follows;

FileInputStream TempIn = new FileInputStream(TempOut);
BufferedReader br = new BufferedReader(new InputStreamReader(TempIn));
for(int i = 0; i < totalNumberOfCaves+1; i++)
{
    br.readLine();
}
String tempRoute = br.readLine();
br.close();

BufferedWriter writeRoute = new BufferedWriter(new FileWriter(FileOut));
writeRoute.write(tempRoute);
writeRoute.close();

However I am getting an error staring

Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at Dijkstra.main(Dijkstra.java:169)

Line 169 relates to the following writeRoute.write(tempRoute);

I am unsure as to why I am getting this error, any advice would be appreciated.

Thanks.

bdg
  • 465
  • 6
  • 18

0 Answers0