In my application I have client and server programms, whenever server got connection from client the server will send all the available id’s from MySQL table to client, for this I have used while loop to read the contents of file.
I tried the following code:
while((a=in.read())!=-1)
but my problem when there is no contents in file to read the while loop is not exiting, it is stopping there itself. How to exit the while loop?
in.read()will block till data is available to be read. Refer the API docs http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read()You can do
in.available()to check if any byte is available to read before doing in.read().