没有必要这样复杂。
Socket s;
DataInputStream io_in;
int i;
.....io_in=s.getDataInputStream();
...
i=in_in.readInt();

解决方案 »

  1.   

    谢谢lisn(翱翔一派).还有一问题,在java中,能将byte类型强制转换成int吗?如
    byte[] a={'0','0','0','1'};
    怎样转换成整数
      

  2.   

    理论上说byte是一个字节,8位,可以转换
    在c里面可以
    BYTE a[]={'0','0','0','1'};
    int *x;
    x=(int *)a;

    因为int是4个字节,所以刚好把a全部包括进去了
    所以这时候x的值是16进制的0X31303030,低字节在前,高字节在后
      

  3.   

    往往是取得内存的copy会有这样的问题,byte->int,简单的转换就行了,不过byte(8bit),int(32bit),丢失精度.
    你的问题是2byte->1int,网络顺序是高位在前低位在后.你要手工转,我就是用了苯办法,用了个switch语句,不过有更好的方法,用移位更好,我没有时间来改写,你也可以手工转一下.
      

  4.   

    BigInteger(byte[] val) 
              Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger. 
    BigInteger(int signum, byte[] magnitude) 
              Translates the sign-magnitude representation of a BigInteger into a BigInteger. 
      

  5.   

    byte[] a={'0','0','0','1'};
    BigInteger bi = new BigInteger(a);
    int i = bi.intValue();
      

  6.   

    你可要送分哟!!
    public static int byteToint(byte[] convertByteValue)
         { byte[] YY=new byte[4];
          YY=convertByteValue;
          int ee, ff, gg, hh;
          ee = YY[3] & 0x000000ff;
          //System.out.println("ee: " +ee);
          ff = (YY[2]<<8) & 0x0000ff00;
          //System.out.println("ff: " +ff);
          gg = (YY[1]<<16) & 0x00ff0000;
          // System.out.println("gg: " +gg);
          hh = YY[0]<<24;
          // System.out.println("hh: "+hh);
          int jj = ee + ff + gg + hh;
          // System.out.println("jj: "+jj);
          return jj;
          }    // Function :About the convert of int to byte array
        public byte[] intTobyte(int convertIntValue)
         { int Y;
           Y = 1321432453;
           byte YY[] = new byte[4];
           Integer aa = new Integer(Y);
            YY[3] = aa.byteValue();
           Integer bb = new Integer(Y>>>8);
            YY[2] = bb.byteValue();
           Integer cc = new Integer(Y>>>16);
            YY[1] = cc.byteValue();
           Integer dd = new Integer(Y>>>24);
            YY[0] = dd.byteValue();
            return YY;
            }
      

  7.   

    http://www.csdn.net/expert/topic/120/120738.shtm