Properties 路径设置--servlet下的设置

//根据key读取value
	public String readValue() {
		 // 返回Servlet上下文路径。
		 String filePath = "/config/paper.properties";
		 String key = "pvalue";
		 
         String path = this.getServletContext().getRealPath("/");
         path = path.substring(0, path.length() - 1);
         path = path + "/WEB-INF/classes"+filePath;
         
         System.out.println("path===============1"+path);
	     Properties prop = new Properties();
	     try {
	    	    FileInputStream input = new FileInputStream(path);
	    	    prop.load(input);
	            String value = prop.getProperty (key);
	            return value;
	        } catch (Exception e) {
	           e.printStackTrace();
	           return "50";
	      }
	}


你可能感兴趣的:(Web,servlet)