我正在嘗試讀取jar文件中的文件夾,它不能以jar格式正常工作,但是當我將它jar時,它會返回nullpointerexpcetion,因爲它無法找到文件也不是目錄在jar文件中的目錄中讀取文件
所以,這裏是我有方法....
public void preloadModelsTwoOLD() {
String slash = System.getProperty("file.separator");
File file = new File("."+ slash +"Patches" + slash+"Models"+slash);
File[] fileArray = file.listFiles();
for(int y = 0; y < fileArray.length; y++) {
String s = fileArray[y].getName();
if (s != "") {
byte[] buffer = readFile("."+ slash +"Patches" + slash+"Models"+slash+""+s);
Model.method460(buffer, Integer.parseInt(getFileNameWithoutExtension(s)));
//System.out.println("Read model: " + s);
}
}
}
基本上這是在罐子裏面 一個java文件和罐子有這個目錄有文件,我需要它讀取
file.java在主文件夾中 主文件夾/班/補丁/型號 但類文件讀取的類文件夾,所以我必須像這樣 ./patches/models/+i+.dat
任何想法,爲什麼它不能正確讀取它以及如何解決它,所以它會工作在jar格式,如果不是兩種格式? 任何幫助表示讚賞。
可能的重複[如何列出JAR文件中的文件?](http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-文件) – Snicolas 2012-03-25 20:34:49