黑马程序员技术交流社区

标题: 关于TCP上传图片 [打印本页]

作者: zl78365336    时间: 2013-11-21 20:35
标题: 关于TCP上传图片
请各位师兄帮忙看看,这是我自己写的
         试过了,可以运行
没显示OK,到底有哪些错误?
-------------------------------------------------
package test;

import java.net.*;
import java.io.*;

public class PicServer {
        public static void main(String[] args) throws Exception {               
                ServerSocket ss = new ServerSocket(10059);
                Socket s = ss.accept();
                BufferedInputStream bufIn =
                                new BufferedInputStream(s.getInputStream());
                BufferedOutputStream bufOut =
                                new BufferedOutputStream(new FileOutputStream("E:\\zz.jpg"));
                int by;
                while((by=bufIn.read())!=-1){
                        bufOut.write(by);
                }
               
                PrintWriter out = new PrintWriter(s.getOutputStream(),true);
                out.println("OK".getBytes());
                bufOut.close();
                s.close();
                ss.close();
        }
}
----------------------------------------------------

package test;

import java.net.*;
import java.io.*;

public class PicClient {
        public static void main(String[] args) throws Exception {
                Socket s = new Socket("192.168.1.101",10059);
                BufferedInputStream bufIn =
                                new BufferedInputStream(new FileInputStream("E:\\008.jpg"));
                BufferedOutputStream bufOut =
                                new BufferedOutputStream(s.getOutputStream());
                int by;
                while((by=bufIn.read())!=-1){
                        bufOut.write(by);
                }
                s.shutdownOutput();
               
                BufferedInputStream bis = new BufferedInputStream(s.getInputStream());
                if((by=bis.read())!=-1)
                        bufOut.write(by);
                bufIn.close();
                s.close();
        }
}

------------------------------------------------






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2