/** * * @param path 文件路径 * @return 文件转成字节数组 */ public static byte[] getByteArrayFrom(String path){ byte[] result=null; ByteArrayOutputStream outputStream=new ByteArrayOutputStream(); //创建文件 File file=new File(path); FileInputStream fileInputStream=null; try { fileInputStream=new FileInputStream(file); int len=0; byte[] buffer=new byte[1024]; while((len=fileInputStream.read(buffer))!=-1){ outputStream.write(buffer, 0, len); } result=outputStream.toByteArray(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(fileInputStream!=null){ try { fileInputStream.close(); fileInputStream=null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return result; }
时间: 2024-10-13 12:17:06