package tools; import java.io.*; public class filetobytes { public static byte[] Filetobyte(File tradeFile){ byte[] buffer = null; try { FileInputStream fis = new FileInputStream(tradeFile); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); }catch (FileNotFoundException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); } return buffer; } public static File getFile(byte[] bfile, String filePath,String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if(!dir.exists()||!dir.isDirectory()){//判断文件目录是否存在 dir.mkdirs(); } file = new File(filePath+"\\"+fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bfile); bos.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return file; } }

annazhang LV29
2023年4月8日
Tuxxxxx LV3
2023年1月3日
高金磊abc LV12
2022年3月18日
TerryGaoBo LV9
2021年8月16日
wjh12345654321 LV14
2021年7月27日
zhaojialiang LV7
2021年5月14日
85489354756a LV3
2021年3月6日
3969138 LV15
2020年11月11日
ehewhee LV6
2020年9月11日
六弄咖啡馆 LV4
2020年6月6日