I assembly my project to a jar with maven, and the there is a "data" folder contained a lot of .bat files inside the jar, the structure is: jar--- ---data(this folder contains 1.bat,2.bat...) ..... I used the method in How do I list the files inside a JAR file?, but when I run the jar in cmd, there still is the NullPointerException, I tried a lot and don't know where is the problem. my code is :
CodeSource src=ParcelLayerTree.class.getProtectionDomain().getCodeSource();
List<String> list=new ArrayList<String>();
if(src!=null){
URL jar=src.getLocation();
ZipInputStream zip=new ZipInputStream(jar.openStream());
ZipEntry zipEntry=null;
while((zipEntry=zip.getNextEntry())!=null){
String entryName=zipEntry.getName();
if(entryName.endsWith(".dat")){
list.add(entryName);
}
}
}
if(list.size()<=0){
throw new IOException("not found the dat file");
}
for (String filePath : list) {
String fileName=fileNameSplit(filePath);
InputStream inputStream=ParcelLayerTree.class.getClassLoader().getResourceAsStream(fileName);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
int label = Integer.parseInt(fileName.split("\\.")[0]);