请问谁知道怎么修改jar包中的xml文件啊,不想采用先解压修改在压缩的办法,文件目录aaa.jar中有个template文件夹下面的abc.xml  想通过java程序修改abc.xml文件!

解决方案 »

  1.   

    只是正常修改的话,winrar直接修改就可以。
    程序的话必须先解压再压缩,因为修改其中一个文件,压缩的字典都变了。
      

  2.   

    不能改,jar 包中的东西应该是只读的。PS:为什么要把需要修改的东西打到 jar 包里面去?这种做法本身就有问题!
      

  3.   

    是可以改的,使用  JarOutputStream, JarInputStream.  给个代码片断供参考, public void encrpt(String jarfile, String desFile) throws IOException {
    String tempDesFile=desFile;
    if(jarfile.equalsIgnoreCase(desFile)){
    tempDesFile+="_tem";
    }

    File f = new File(tempDesFile);
    if (f.exists()) {
    f.delete();
    }

    JarOutputStream jaros = new JarOutputStream(new FileOutputStream(
    tempDesFile));
    JarFile jarf = new JarFile(jarfile);
    // byte[] buf = new byte[1024];
    for (Enumeration<JarEntry> en = jarf.entries(); en.hasMoreElements();) {
    JarEntry entry = en.nextElement(); jaros.putNextEntry(new JarEntry(entry.getName())); InputStream entryIn = jarf.getInputStream(entry); byte[] encryData;
    byte[] classData = getByteData(entryIn); String extName = "";
    int index = entry.getName().lastIndexOf(".");
    if (index != -1) {
    extName = entry.getName().substring(index + 1);
    }
    if (this.encyptType.contains(extName) && crptor != null) {
    encryData = crptor.encrpt(classData);
    } else {
    encryData = classData;
    }
    jaros.write(encryData, 0, encryData.length); jaros.closeEntry();
    }
    jarf.close();
    jaros.close();

    Util.rename(tempDesFile, desFile);
    }
      

  4.   

    请问能不能结合dom修改XML呢?
      

  5.   

    其实 在dos下输入命令jar uf test.jar manifest.xml就可以覆盖掉manifest.xml文件了,当然目录结构要弄清楚。
      

  6.   

    为什么要改的东西还要打到jar里面去???