(转)[Java]文件转二进制
原创
©著作权归作者所有:来自51CTO博客作者james_karon的原创作品,请联系作者获取转载授权,否则将追究法律责任
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;
}