从带有套接字的服务器读取
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* 时 代 Java 公 众 号 - nowjava.com 提供 */ import java.io.PrintStream; import java.net.Socket; public class Main { public static void main(String[] arguments) { try (Socket digit = new Socket("127.0.0.1", 79); BufferedReader in = new BufferedReader(new InputStreamReader( digit.getInputStream()));) { digit.setSoTimeout(20000); PrintStream out = new PrintStream(digit.getOutputStream()); out.print("\015\012"); /** n o w j a v a . c o m 提供 **/ boolean eof = false; while (!eof) { String line = in.readLine(); if (line != null) { System.out.println(line); }