`

(转)[Java]文件转二进制

    博客分类:
  • Java
阅读更多

转自:https://blog.csdn.net/weixin_36022745/article/details/84637515

 

public static byte[] fileToByte(String filePath) throws IOException{
    byte[] bytes = null;
    FileInputStream fis = null;
    try{
        File file = new File(filepath);
        fis = new FileInputStream(file);
        bytes = new bytes[(int) file.length()];
        fis.read(bytes);
    }catch(IOException e){
        e.printStackTrace();
        throw e;
    }finally{
        fis.close();
    }
    return bytes;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics