请问谁知道怎么修改jar包中的xml文件啊,不想采用先解压修改在压缩的办法,文件目录aaa.jar中有个template文件夹下面的abc.xml 想通过java程序修改abc.xml文件!
解决方案 »
- Executors.newSingleThreadScheduledExecutor中的异常处理
- xml中如何包含&等特殊字符?
- 【网路时代】批判夸大Web2.0的另一种婉转说词
- 在JTable里如何加JButton?
- 在线急等 short i=97; char c = i;为什么会提示精度丢失?
- Eclipse能不能像JBuilder一样进行可视化的界面设计
- 为什么这个泛型程序没有输出?
- 我现在刚开始学JAVA,我想问一下SUM有没有象微软的MSDN那样的资料?
- 如何删调一个文件!在线等待,急!
- 连接数据库时出现[Message][ODBC 驱动程序 管理器]非法的描述器索引。是什么问题?
- 求助,17的args.length是否会编译或运行时错误?
- JAVA中是否有C++的指向函数的指针这个概念?
程序的话必须先解压再压缩,因为修改其中一个文件,压缩的字典都变了。
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);
}