Newbie: Determining end of file

I'm trying to write a mini-browser in Java. I can send out the HTTP
request OK, but my code that receives the file doesn't know when to
quit. It looks (roughly) like this:

	// [in = the input stream of the socket I create]
	// [outfile = the file to dump the response into]
	String line;
	while ((line = in.readLine()) != null)
		outfile.println(line);

Pretty basic. But it doesn't always work. Sometimes it works, sometimes
it hangs forever, waiting for the last read. It depends on the page, and
it's consistent (if it hangs on a certain page, then it *always* hangs
on that page). Reading in one character at a time is inconsistent also.

Should I be reading the Content-Length value and using it, instead of
this lazy 'read-until-you-tell-me-not-to' approach? 

Thanks,
Chris

Received on Friday, 13 February 1998 16:47:37 UTC