隨筆-2  評論-6  文章-5  trackbacks-0

          忙了一天就為了把幾個文件變成zip包:
          發(fā)現(xiàn):1,java的zip中文有問題用ant的
          ???????????? 2,只能生成zip,不能往原有的zip里面添加?xùn)|西

          /**
          ? *
          ? * @param list 準(zhǔn)備壓縮文件bean列表,bean里面是壓縮文件的路進和名字
          ? * @param outDir 輸出路徑
          ? * @param outName? 輸出文件名
          ? */
          ?
          ?public static void zipFilesAntJar(List list,String outDir,String outName){
          ??FileOutputStream fout;
          ??org.apache.tools.zip.ZipOutputStream zipOut;
          ??try {
          ???fout = new FileOutputStream(outDir+outName);
          ???
          ???zipOut = new org.apache.tools.zip.ZipOutputStream(fout);
          ???for (Iterator iter = list.iterator(); iter.hasNext();) {
          ????FileBean fb = (FileBean) iter.next();
          ????
          ?????FileInputStream fin = new FileInputStream(fb.getPathName());
          ?????
          ?????zipOut.setEncoding("GBK");
          ?????zipOut.putNextEntry(new org.apache.tools.zip.ZipEntry(fb.getName()));
          ?????
          ?????int number = 0;
          ?????byte[] b = new byte[1024];
          ?????while((number=fin.read(b))!=-1){
          ??????zipOut.write(b, 0, number);
          ?????}
          ?????zipOut.flush();
          ?????fin.close();
          ????
          ???}
          ???zipOut.close();
          ???fout.close();
          ??} catch (FileNotFoundException e) {
          ???e.printStackTrace();
          ??} catch (IOException e) {
          ???e.printStackTrace();
          ??}
          ??
          ?}

          public class FileBean {
          ?private String path;
          ?private String name;
          ?
          ?public FileBean(String path,String name){
          ??this.path = path;
          ??this.name = name;
          ?}
          ?public String getName() {
          ??return name;
          ?}
          ?public void setName(String name) {
          ??this.name = name;
          ?}
          ?public String getPath() {
          ??return path;
          ?}
          ?public void setPath(String path) {
          ??this.path = path;
          ?}
          ?public String getPathName(){
          ??return path+name;
          ?}
          }

          ?

          posted on 2007-03-27 17:19 tornado 閱讀(396) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 耒阳市| 尚义县| 汝南县| 平泉县| 陇川县| 凌源市| 呈贡县| 房产| 信阳市| 弥勒县| 古田县| 新乡市| 邵东县| 登封市| 临沭县| 巴中市| 新宁县| 丘北县| 韶山市| 鄄城县| 敦化市| 交口县| 河西区| 康保县| 增城市| 阳谷县| 门源| 宜章县| 澳门| 伊川县| 林州市| 吴桥县| 麻江县| 修武县| 鹿泉市| 岳阳县| 涪陵区| 卓尼县| 柏乡县| 沙河市| 石家庄市|