服务器端的代码
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.net.ServerSocket;import java.net.Socket;import java.util.UUID;/** * 服务器端的实现 * @author L.Eric * */public class UploadPicServer {public static void main(String[] args) throws IOException {RecivePic(7878,"png");} /** * @Description: TODO * @param port 绑定服务器端的端口 * @param ext 上传文件的扩展名 * @throws IOException * @author L.Eric * create: 2013-4-27 */public static void RecivePic(int port, String ext) throws IOException{System.out.println("服务器端启动....");ServerSocket ss = new ServerSocket(port);//接收服务器端的请求Socket s = ss.accept();//输出流,用于输出接收的图片字节流BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(UUID.randomUUID()+""+"."+ext)));//接收客户端的输出流的信息BufferedInputStream bis = new BufferedInputStream(s.getInputStream());//输出信息到客户端PrintWriter out = new PrintWriter(s.getOutputStream(), true);int len = 0;byte[] buf = new byte[1024];while((len = bis.read(buf, 0, buf.length)) != -1) {bos.write(buf, 0, len);//刷新缓冲区bos.flush();}out.println("true");bos.close();s.close();ss.close();}}import java.io.BufferedInputStream