We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
public void zipFiles(){ FileOutputStream fos = null; ZipOutputStream zipOut = null; FileInputStream fis = null; try { File folder = new File("D:\Data\attachment"); File[] attachFiles = folder.listFiles(); fos = new FileOutputStream("C:\Users\admin\Desktop\tai-lieu\testing.zip"); zipOut = new ZipOutputStream(new BufferedOutputStream(fos)); for(File file: attachFiles){ fis = new FileInputStream(file); ZipEntry ze = new ZipEntry(file.getName()); System.out.println("Zipping the file: "+file.getName()); zipOut.putNextEntry(ze); byte[] tmp = new byte[1024]; int size = 0; while((size = fis.read(tmp)) != -1){ zipOut.write(tmp, 0, size); } zipOut.flush(); fis.close(); } zipOut.close(); System.out.println("Done... Zipped the files..."); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try{ if(fos != null) fos.close(); } catch(Exception ex){ } } }
MimeBodyPart attachmentPart = new MimeBodyPart(); attachmentPart.attachFile(new File("path/to/file"));
C:\Users\admin\Desktop\tai-lieu\testing.zip
"path/to/file"
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Input your email to receive reset password link, or if you remember your password, you can click