我有以下的結構,我的Eclipse項目:如何在靜態上下文中訪問文件?
我要訪問的文件lito.properties與方法的FileInputStream。
在網上搜索,我發現這個解決方案:
FileInputStream file = (FileInputStream) this.getClass().getResourceAsStream("/files/lito.properties");
這似乎是做到這一點的最好辦法,但如果我在一個靜態方法我工作? 它總是給這個錯誤:
Cannot use this in a static context
所以,我該怎麼做才能訪問該文件在靜態情況下?
爲什麼不把'ResourceBundle'的優勢在哪裏? http://www.avajava.com/tutorials/lessons/how-do-i-read-a-properties-file-with-a-resource-bundle.html – 2014-10-10 17:40:58