base64encoding java中的压缩文件夹

时间:2012-03-16 17:42:59

标签: java encoding zip base64

我的任务是对压缩文件夹进行base64编码。我正在使用Apache的Commons-Codec来执行此功能。但我只能单独编码文件并将其放入zip文件夹,而不是相反。任何人都可以指导我吗?我特此附上我所尝试的内容;

                     try
                   {
                      ZipOutputStream out = new ZipOutputStream
                      (new FileOutputStream("G:\\new.zip"));
                      byte[] data = new byte[1000]; 
                      File file = new File("G:\\test1.txt");
                      BufferedInputStream in = new BufferedInputStream
                      (new FileInputStream(file));
                       int count;
                       out.putNextEntry(new ZipEntry(file.getName()));
                       while((count = in.read(data,0,1000)) != -1)
                       {  
                      out.write(data, 0, count);
                       }
                      in.close();
                      out.flush();
                      out.close();
                      System.out.println("zipped");
                       }
                      catch(Exception e)
                       {
                      e.printStackTrace();
                      }  
                    }

上面的代码帮助我将文件压缩到一个文件夹并对这个文件夹进行编码,我添加了这段代码,这给了我很多错误;

              byte encodedBuf[] = new byte[(int) f.length()];
              in.read(encodedBuf);
              byte enc [] = org.apache.commons.codec.binary.Base64.encodeBase64(encodedBuf);
              out.write(enc, 0, enc.length);

               }

我的问题在于整合部分。我不知道如何集成它以获得编码的压缩文件夹。

0 个答案:

没有答案