运行TestClient的时候就报错?报错的问题实在看不懂请大神指导一下,然后告诉错误在哪里谢谢了!
- import java.io.*;
- import java.net.*;
- class TestClient
- {
- public static void main(String[] args)throws Exception
- {
- Socket s=new Socket("192.168.1.113",10006);
- BufferedReader bufr=new BufferedReader(new FileReader("D:\\javaDemo\\TcpDemo.java"));
- PrintWriter bufOut=new PrintWriter(s.getOutputStream(),true);
- String line=null;
- while((line=bufr.readLine())!=null){
- bufOut.println(line);
- }
- s.shutdownOutput();
- BufferedReader bufIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
- String str=bufIn.readLine();
- System.out.println(str);
- bufr.close();
- s.close();
-
- }
- }
- class TestServer
- {
- public static void main(String[] args)throws Exception{
- ServerSocket ss=new ServerSocket(10006);
- Socket s=ss.accept();
- String ip=s.getInetAddress().getHostAddress();
- System.out.println(ip+"连接成功");
- BufferedReader bufIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter out=new PrintWriter(new FileWriter("D:\\javaDemo\\Server.txt"),true);
- String line=null;
- while((line=bufIn.readLine())!=null){
- out.println(line);
- }
- PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
- pw.println("上传成功");
- out.close();
- s.close();
- ss.close();
-
- }
- }
复制代码 |
|