JAR文件不承认我读JAR文件的更新

问题描述 投票:0回答:1

我使用NetBeans和我的节目,我正在读的文件。当我运行它,它正确地读取文件。当我建立该程序的JAR也可以正常工作。但是,当我改变,我从阅读的文件,在我的build目录,我的JAR没有相应的更新。为什么会这样?是否有一个解决方案?

下面的代码显示我怎么读我的程序文件。提前致谢。

InputStream in = NewJFrame.class.getResourceAsStream("/holidays.txt"); 
BufferedReader readHolidays = new BufferedReader(new InputStreamReader(in));
String line;
line = readHolidays.readLine();

while(line != null) {
    //read into hashmaps
    //...
    line = readHolidays.readLine();
}
readHolidays.close();
java netbeans jar inputstream
1个回答
0
投票

没关系,我得到它;)如果任何人需要这样的:基本上我每次运行程序时我发现的文件路径的jar文件,并从那里我阅读的文本文档。

File jarFile = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); 

FileInputStream is = new FileInputStream(jarFile.getParent().toString() + "/file.txt"); BufferedReader readFile= new BufferedReader(new InputStreamReader(is));
© www.soinside.com 2019 - 2024. All rights reserved.