发送的时候不能用writeUTF()
应该使用字节流,OutputStream
因为这些字节是不能进行任何编码的

解决方案 »

  1.   

    DataOutputStream out;out.writeUTF(new String(classByteOfServerClass));这样不行是吗?可我测试发现字符和图形以及字节数没什么两样啊?
      

  2.   

    DataOutputStream out;
    out.write(classBytes);
    out.flush();
    这样直接发送byte[]
      

  3.   

    接受使用DataInputStream
    还是用byte[]接收啊
      

  4.   

    我的意思是
    byte[] buffer=new byte[这里怎么刚好是字节数呢?];
    in.read(buffer);
    不然定义不出来类啊
      

  5.   

    接收的时候要用缓存
    也就说
    byte[] buffer=new byte[BUFFER_SIZE];
    while(in.read(buffer)!=-1) {...
    }
      

  6.   


    上面说的还不够详细吗
    我觉得你的问题就在于用了UTF编码传递byte现在你全部直接传递byte数组,应该就没有问题
    发送端你已经会了
    接收端用循环每次读取一定大小的byte,然后最后拼接成的就是一个完整的byte[]了
      

  7.   

    晕,我说了用循环啊
    比如:
    byte []temp=new byte[256];
    byte []result;
    while(in.read(temp)!=-1)  {
    //result的数组最后加上得到的这个temp数组的值
    }
    最后result的就是拼装出来的结果
      

  8.   

    你的意思是要直接写入文件?
    那么就更简单了
    FileOutputStream out=new FileOutputStream("xxx.class"); 
    byte []temp=new byte[256];
    int i=0;
    while((i=in.read(temp))!=-1)  {
    out.write(temp,0,i);
    temp=new byte[256];
    }
      

  9.   

    我不知道给分.请斑竹给 jFresH_MaN(TM) 50分.
      

  10.   

    呵呵!
    看看java网络编程也许会好点。^_^