I imagine "getchar" is a
String that's initialized to "" -- you haven't shown its declaration.
read() doesn't return "0" except when you read the character whose value is 0; read() returns -1 to indicate end of file, so your loop should
test for -1. If your file doesn't contain a 0 -- and text files generally won't! -- then this will loop forever. Change that 0 to a -1 and this will work.
That said, this is
horrifying code -- it's about the least efficient way to read a file into a String that I could imagine. Something like this is infinitely better: