public static byte[] fileToZip(){ ZipOutputStream append = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { append = new ZipOutputStream(bos); ZipEntry e = new ZipEntry("request.xml"); append.putNextEntry(e); append.write(filteToByte("G:\\tmp\\request.xml")); append.closeEntry(); e = new ZipEntry("CONTENT\\content.xml"); append.putNextEntry(e); append.write(filteToByte("G:\\tmp\\content.xml")); append.closeEntry(); } catch (FileNotFoundException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } finally{ if(null != append){ try { append.close(); } catch (IOException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } } } return bos.toByteArray(); }
时间: 2024-09-29 20:08:02