The condition for the while loop is that (a != 1). the variable a is set before the loop starts by reading from the file. There is nothing inside the loop to tell it to stop and read more input from the file. Whatever the single int value is it read from the file, that is what it keeps using in the condition.
Why on earth are you using read()? A dreadful method. I hope it is only so you can see how it works, or maybe so you can see how it doesn't work.
If you really want to read a text file, don't use an input stream. Use a file reader and wrap it in a buffered reader. Or, better, a Scanner. Or better still, NIO2.
But start by going through the Java® Tutorials, as I gave you a link to earlier. You may end up with strange syntax like this:-It looks strange but it is an effiecient way to read every line in a text file with a Buffered Reader.