Java通过接口返回文件流

时间:2025-01-19 10:25:59
public byte[] fileUrlToBytes(String fileUrl) { FileInputStream inputStream = null; byte[] bytes = null; try { File file = new File(fileUrl); inputStream = new FileInputStream(file); bytes = new byte[inputStream.available()]; inputStream.read(bytes,0,inputStream.available()); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return bytes; }