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

          忙了一天就為了把幾個文件變成zip包:
          發現:1,java的zip中文有問題用ant的
          ???????????? 2,只能生成zip,不能往原有的zip里面添加東西

          /**
          ? *
          ? * @param list 準備壓縮文件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 閱讀(397) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 海口市| 潮安县| 阿巴嘎旗| 理塘县| 南溪县| 七台河市| 南宫市| 成都市| 顺平县| 阳山县| 景宁| 新河县| 驻马店市| 沂南县| 东莞市| 凤阳县| 伊春市| 柳林县| 南康市| 桐庐县| 阿鲁科尔沁旗| 台前县| 广丰县| 三都| 剑川县| 巨野县| 普兰店市| 皋兰县| 金溪县| 澳门| 清流县| 鄂伦春自治旗| 米泉市| 洪江市| 班玛县| 海城市| 鞍山市| 新乡县| 方城县| 车致| 西丰县|