CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while(true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; String name = e.getName(); if (name.startsWith("path/to/your/dir/")) { ... } }} else { }
请注意,在Java 7中,你可以
FileSystem从JAR(zip)文件创建一个,然后使用NIO的目录遍历和过滤机制在其中进行搜索。这将使编写处理JAR和“爆炸”目录的代码更加容易。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)