java将文件转为字节数组
/** * 将文件转为字节 * @param listPd * @return */ public static byte[] t3(String path){ File file = new File("F:/util02/apache-tomcat-8.5.23/driverImgs/"+path); FileInputStream stream =null; ByteArrayOutputStream bos =null; byte[] bs; try { stream = new FileInputStream(file); bos = new ByteArrayOutputStream(); bos.write(stream); bs = bos.toByteArray(); } catch (Exception e) { // TODO Auto-generated catch block return new byte[1]; }finally { if(bos!=null){ try { bos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(stream!=null){ try { stream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return bs; }