生活随笔
收集整理的這篇文章主要介紹了
删除jar包中的指定文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
如何刪除jar包中的指定文件呢?
當(dāng)然使用解壓縮軟件(rar,zip,7z)肯定沒問題.但是我想自動(dòng)化,圖形界面的工具就無能為力了.
核心方法:
Java代碼??
????????????public?static?void?deleteFileInJar(String?jarPath,String?fileName)?throws?IOException,?ArchiveException{??????????List<String>fileNames=new?ArrayList<String>();??????????if(!ValueWidget.isNullOrEmpty(fileName)){??????????fileNames.add(fileName);}??????????deleteFileInJar(jarPath,?fileNames);??????}??????????????????public?static?void?deleteFileInJar(String?jarPath,List<String>fileNames)?throws?IOException,?ArchiveException{??????????List<ZipFileBean>?zipFiles?=?CompressZipUtil??????????????????.deCompressRecursionFileList(jarPath,?"",?true);??????????List<ZipApkFile>?zipApkFiles?=?extendZipFileBean(zipFiles,fileNames);??????????CompressZipUtil.setPrint(false);??????????File?newFile=new?File(jarPath?+?".bak");??????????while(newFile.exists()){????????????????????????????System.out.println("file?exist:"+newFile.getAbsolutePath());??????????????newFile=new?File(jarPath?+?RandomUtils.getTimeRandom2());??????????}??????????CompressZipUtil.persistenceZip(newFile,?zipApkFiles);??????????File?jarFile=new?File(jarPath);????????????????????System.out.println("delete?old?jar:"+jarFile.getAbsolutePath());??????????boolean?isSuccess=jarFile.delete();??????????if(!isSuccess){??????????????System.out.println("刪除失敗:"+jarFile.getAbsolutePath());??????????}else{??????????????System.out.println("modify?name");??????????????newFile.renameTo(jarFile);??????????}??????}?? ?使用說明:
比如我想刪除jar(zip)包中的config\manual.properties
zip包結(jié)構(gòu):
?
main方法如下:
?
Java代碼??
public?static?void?main(String[]?args)?throws?IOException,?ArchiveException?{??????????String?jarPath="D:\\bin\\config\\config.zip";????????????deleteFileInJar(jarPath,?"config/manual.properties");??????????System.out.println("jarPath:"+jarPath);??????????????????} ?
總結(jié)
以上是生活随笔為你收集整理的删除jar包中的指定文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。