文件传送(服务端能响应多个请求)——dosy

来源:互联网 发布:武藏300ds点胶机编程 编辑:程序博客网 时间:2024/05/20 23:03
import java.io.*;import java.util.*;import java.net.*;class serone extends Thread{ private Socket ser;  File inputfile = new File("dos.csf"); public serone(Socket s){  this.ser = s; }   public void run(){   try{    BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputfile));    BufferedOutputStream ou = new BufferedOutputStream ((ser.getOutputStream()));    int c;   while((c=in.read())!=-1)    ou.write(c);    in.close();    ou.close();   }catch(Exception e){    System.out.println(e.toString());   }}}public class test { public static void main(String[] args)throws Exception{  ServerSocket s = new ServerSocket(12312);  try{   while(true){    try{      Socket ser = s.accept();     System.out.println("connection already.....");     (new serone(ser)).start();     //tt.start();    }    catch(IOException e){     //ser.close();     System.err.println(e.toString());    }    }  }      finally{    s.close();   }   }}
原创粉丝点击