把文件打包成一个.jar文件在传输吧!

解决方案 »

  1.   

    将文件名放在一个String数组里面,循环读取。
      

  2.   

    File类的list 方法反回一个数组
    然后用个for就可以了
      

  3.   

    用File的list方法返回一个数组
    然后再用一个for
      

  4.   

    觉得实用的应该是自己定义自己的传送协议,比如:
        一个文件开始传送 -> 
        文件流 -> 
        一个文件传送结束 
       ...循环以上
      

  5.   


    我觉得你的概念要纠正一下。你看过http协议的用法吗?服务器等待着客户,客户要什么文件就问服务器要,而服务器什么都不管,只负责发送客户要求的文件。建议看一下http协议的用法。
      

  6.   

    一段简要的程序,不知道可不可以帮到你。Client:
    ...
    public static void main(String args[]){
      Socket client = new Socket("localhost", 8888);
      String fileName[]={
                      "file1",
                      "file2",
                      "file3"
                    };
      PrintWriter out = new PrintWriter(client.getOutputStream, true);
      for(int i = 0; i < fileName.length; i++){
        FileInputStream fileInput = new FileInputStream(fileName[i]);
        BufferedReader read = new BufferedReader(new InputStreamReader(fileInput));
        String msg;
        while((msg=read.readLine())!=null){
          write.println(msg);
        }
        write.println("****NEXT****");//作为一个标志信息发给服务端
        fileInput.close();
        read.close();
      }
    }Server:
    ...
    public static void main(String args[]){
        ...
        ServerSocket server = new ServerSocket(8888);
        client = serer.accpet();
        BufferedReader read = new BufferedReader(new InputStreamReader(clieng.getInputStream()));
        String msg;
        while((msg=read.readLine())!=null){
          if(msg.equals("****NEXT****")){
            /*处理下一个文件*/
          }
        }
    }
      

  7.   

    用File的list方法返回一个数组
    然后再用一个for
      

  8.   

    newman0708(nch):小弟功力不够啊,可能是又些理解错误。我是这样定义的:
    while(true){
    client 发请求 -》
    S响应
    ClienT 发目录名
    S响应文件名
    S响应文件大小
    C响应
    S发文件流
    }
    这样对不对啊,要是你,你会怎么做啊?
      

  9.   

    OneNight(OneNightStand) 的方法是可以的,只要在传送的时候设置一个标志就可以了!·!!!
      

  10.   

    mycomputermysky(牧野流星) :OnNightStand? 一夜情方法?是什么意思啊?
      

  11.   

    呵呵,能够给我一份:[email protected]
      

  12.   

    能不能也给发一份呢?[email protected]