静态类中获取项目跟路径

public class XMLReader {
	
	public static void readXml(){
		String path = new Object() {
	        public String getPath() {
	            return this.getClass().getResource("/").getPath();
	        }
		}.getPath().substring(1);
		SAXReader reader = new SAXReader();
		String filePath = path+"conf/zbmes.xml";
		try {
			Document document = reader.read(new File(filePath));
			Element rootNode = document.getRootElement();
			String ProjectName = rootNode.elementText("ProjectName");
			CacheManagerImpl.getInstance().putCache("ProjectName", ProjectName, 0);
			
		} catch (DocumentException e) {
			LogUtil.recordErrorToLog(XMLReader.class, "没有找到文件"+filePath);
			
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_21860997/article/details/85156332