请问int如何转换成byte[]?请写个程序说明

解决方案 »

  1.   

    可以先转成string类,在转成byte[]
    例如:public class Test{
         
    public static void main(String args[]){
    int x=312;
    Integer i1=x;
    String s=i1.toString();
    byte[] b=s.getBytes();
    for(int i=0;i<3;i++)
    System.out.println(b[i]);
    }

    输出的就是3,1,2对应的ASCII码
    如果正确
    记得给分哦
      

  2.   

    public static void main(String[] args)
    {
    // TODO 自动生成方法存根
    int a = 4;
    byte[] b = (a+"").getBytes();
    for(byte c : b)
    System.out.println(c);
    }