How to convert a Byte Array to an Int Array

后端 未结 7 1063
生来不讨喜
生来不讨喜 2020-11-28 12:44

I am reading a file by using:

int len = (int)(new File(args[0]).length());
    FileInputStream fis =
        new FileInputStream(args[0]);
    byte buf[] = n         


        
7条回答
  •  自闭症患者
    2020-11-28 13:13

    Create a new int array and copy over the values, casting as needed.

    int[] arr = new int[len];
    
    for(int i = 0; i < len; i++)
        arr[i] = (int)buf[i];
    

提交回复
热议问题