62,628
社区成员
发帖
与我相关
我的任务
分享
public class TCPClient {
public static void main(String[] args) {
Socket s = null;
PrintStream ps=null;
BufferedReader br = null;
try {
s = new Socket("localhost", 20000);
OutputStream out = s.getOutputStream();
ps = new PrintStream(out);
br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while ((line = br.readLine()) != null) {
ps.println(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
s.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
用loaclhost测试没有问题。
while ((line = br.readLine()) != null) {
bw.write(line);
bw.close();
}
