java加载配置文件

/**
	 * 读取配置文件,并返回相应的字符串
	 * @param filename
	 * @return
	 */
	public String readFile(String filename) {
		InputStream is = this.getClass().getClassLoader().getResourceAsStream(filename);
		Properties properties = new Properties();
		try {
			properties.load(is);
			properties.getProperty("username");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return properties.getProperty("username");;
	}

配置文件格式

username=xxx

你可能感兴趣的:(java)