When the program has not yet read from the stream, the ready () method returns false, although in fact there is something to read in the stream. And if you read it once, then ready () works correctly. Why is this so? Here is a sample program:
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.net.Socket; import java.io.IOException; import java.util.*; public class Server { public static void main(String[] args) { try { String ip = ""; //любой работающий веб сервер int port = 25; //любой Socket socket = new Socket(ip, port); InputStreamReader reader = new InputStreamReader(socket.getInputStream()); String str = ""; System.out.println(reader.ready()); str += (char) reader.read(); System.out.println(reader.ready()); while(reader.ready()) { str += (char) reader.read(); } System.out.println("End read - " + str); reader.close(); socket.close(); } catch(IOException exp) { System.out.println("Error"); } } }