久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

java 如何列出jar包中jar包里的所有文件和目錄?

瀏覽:132日期:2024-01-10 17:55:41

問題描述

如這樣一個目錄/Users/xxx/IdeaProjects/abc/web/target/web.jar!/BOOT-INF/lib/rest-0.0.1.jar!/com/tg/tiny/Users/xxx/IdeaProjects/abc/web/target/web.jar這個jar包下的文件目錄可以這樣得到

JarFile localJarFile = new JarFile(new File('/Users/xxx/IdeaProjects/abc/web/target/web.jar'));Enumeration<JarEntry> entries = localJarFile.entries();while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); System.out.println(jarEntry.getName());}

那么這個web.jar里的rest-0.0.1.jar下的文件目錄如何得到?

問題解答

回答1:

URL url = new URL('jar', null, 0, 'file:/Users/xxx/IdeaProjects/web/target/web.jar!/BOOT-INF/lib/rest.jar');URLConnection con = url.openConnection();if (con instanceof JarURLConnection) { JarURLConnection result = (JarURLConnection) con; JarInputStream jarInputStream = new JarInputStream(result.getInputStream()); JarEntry entry; while ((entry = jarInputStream.getNextJarEntry()) != null) {System.out.println(entry.getName()); }}回答2:

jar包是個文件。不是目錄。需要通過classloader的getResourceAsStream()。

package edu.hxraid; import java.io.*; public class Resource { public void getResource() throws IOException{ //返回讀取指定資源的輸入流 InputStream is=this.getClass().getResourceAsStream('/resource/res.txt'); BufferedReader br=new BufferedReader(new InputStreamReader(is)); String s=''; while((s=br.readLine())!=null) System.out.println(s); } }

詳細使用:http://www.myexception.cn/pro...

標簽: java
相關文章:
主站蜘蛛池模板: 平顶山市| 金溪县| 博罗县| 德令哈市| 墨竹工卡县| 罗定市| 清水县| 河北区| 宿松县| 平阳县| 济宁市| 古交市| 铁岭市| 东城区| 汉中市| 高雄县| 关岭| 涪陵区| 马鞍山市| 旌德县| 舒城县| 丹棱县| 晋江市| 紫金县| 中卫市| 大余县| 汉中市| 石林| 麦盖提县| 潢川县| 台北市| 乌拉特中旗| 甘孜| 陈巴尔虎旗| 靖江市| 古交市| 保亭| 额敏县| 奇台县| 沙雅县| 苍溪县|