欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-12 16:13:24
...

转自: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;
}