回覆列表
  • 1 # 呂梁668

    /**

    * 把二進位制檔案轉化為位元組陣列

    * @param path :path of specified file

    * @return bytes[]

    * @throws Exception

    */

    public static byte[] toByteArrFromFile(String path) throws Exception{

    File inFile = new File(path);

    FileInputStream fileInputStream = new FileInputStream(inFile);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    int i;

    //轉化為位元組陣列流

    while ((i = fileInputStream.read()) != -1) {

    byteArrayOutputStream.write(i);

    }

    fileInputStream.close();

    // 把檔案存在一個位元組陣列中

    byte[] bytes = byteArrayOutputStream.toByteArray();

    byteArrayOutputStream.close();

    return bytes;

    }

  • 中秋節和大豐收的關聯?
  • 新型冠狀病毒起源於夏威夷的可能性有多大?