转自:https://blog.youkuaiyun.com/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;
}
本文介绍了一种将文件转换为字节数组的Java方法,该方法使用FileInputStream读取文件并将其内容转换为字节数组,便于在网络中传输或存储。
3万+





