java - Null Pointer Exception at EOF -
so i'm getting null pointer on lastly line of method. i've read on others issue, using while ((linein = myreader.readline()) != null)
should stopping file 1 time has nil left, doesn't seem that. instead end catching npe. can't figure out why is. advice appreciated! band-aid issue using catch (nullpointerexception)
statement, don't sense that's adequate solution.
bufferedreader myreader; seek { fileinputstream fileinstream = new fileinputstream( filelocation); inputstreamreader fileinputstreamreader = new inputstreamreader( fileinstream, "utf-16"); myreader = new bufferedreader(fileinputstreamreader); string linein = ""; // read next line until there aren't left while ((linein = myreader.readline()) != null) { //do stuff line } system.out.println("done"); // close file connections read done. filein.close(); myreader.close(); } grab (exception e) { system.out.println("error: " + e.getmessage()); e.printstacktrace();
}
null pointer should never caught should fixed. not want them propagate remaining parts of code.
also ensure closing file. add together block , close files resources. way if exception caught still close file.
java bufferedreader fileinputstream
No comments:
Post a Comment