[英]Java, I'm not being able to print the whole response on the console
我無法在控制台上打印來自服務器的整個響應,有 3 種方法可以繞過這件事,
我無法關閉連接,因為我想在同一個連接上發送多次,
我只想打印整個響應而不關閉連接。
這是我的代碼:
String Ch2 = "";
sops.write(my_UTF8Byte);
while((Ch2 = reader.readLine()) != null){
System.out.println(Ch2);
//sops.write(my_UTF8Byte);
Thread.sleep(10);
}
//s.close(); This will solve the problem
當您說不打印整個響應時,它缺少最后一行? 通過一次執行一個字符而不是 readLine 來檢查:
int ch;
while((ch = in.read()) != -1)
{
System.out.print((char)ch);
}
我很久以前就遇到過這個問題。 在您的 OutputStream 上調用 flush() 應該可以解決您的問題。
sops.flush
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.