讀取web項目文件的時候,可以先切換到Navigator(myeclipse)視圖,然後找到你需要讀取的文件。例如我的文件是在WebRoot --->WEB-INF ---> a.properties。
那麼我們可以
String path = System.getProperty("webapp.root")
+ "WEB-INF" + File.separator + "classes" + File.separator + "a.properties";
path就是你的文件在該項目的地址了。
System.setProperty("source.path", path);
你就可以在別的地方 根據
System.getProperty("source.path")
獲取到你的文件路徑。