-1

我如何在jar中加载txt文件?不能用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();
    }
4

1 回答 1

0

您不是在阅读实际文件,请使用:

InputStream in = getClass().getResourceAsStream("/DataBase.txt");
ObjectInputStream ios = new ObjectInputStream(in);
于 2013-10-12T03:48:06.237 回答