小编Ign*_*cio的帖子

我怎么能用Java压缩文件而不包括文件路径

例如,我想压缩存储在/Users/me/Desktop/image.jpg中的文件

我做了这个方法:

public static Boolean generateZipFile(ArrayList<String> sourcesFilenames, String destinationDir, String zipFilename){
  // Create a buffer for reading the files 
  byte[] buf = new byte[1024]; 

  try {
   // VER SI HAY QUE CREAR EL ROOT PATH
         boolean result = (new File(destinationDir)).mkdirs();

         String zipFullFilename = destinationDir + "/" + zipFilename ;

         System.out.println(result);

   // Create the ZIP file  
   ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFullFilename)); 
   // Compress the files 
   for (String filename: sourcesFilenames) { 
    FileInputStream in = new FileInputStream(filename); 
    // Add ZIP entry to …
Run Code Online (Sandbox Code Playgroud)

java zip java-io

19
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

java-io ×1

zip ×1