I've massaged your code so that it can read a PGM header file. I could only test with an example PGM that was way too big to fit in a teensy, so I can't guarantee that it'll read the image itself correctly.
// Read a...
Many years ago, I had a Java crash whenever I opened a fairly large project and tracked it down to an unterminated comment. Maybe that's now been fixed but keep it in mind if all else fails ;)
Pete