如何在jar中加载文本文件?
无法使用getClass().getResource("/DataBase.txt");
public static void readFromFile() throws FileNotFoundException, IOException, ClassNotFoundException{
FileInputStream fis = new FileInputStream(f);
ObjectInputStream ois = new ObjectInputStream(fis);
Authorisation.userMap = (HashMap<String, User>) ois.readObject();
ois.close();
}
答案 0 :(得分:0)
您没有阅读实际文件,请使用:
InputStream in = getClass().getResourceAsStream("/DataBase.txt");
ObjectInputStream ios = new ObjectInputStream(in);