Skip to content

Instantly share code, notes, and snippets.

@yinchunxiang
Last active June 20, 2017 11:25
Show Gist options
  • Save yinchunxiang/bc795abbb3a6d09ba39a1b87125f6c92 to your computer and use it in GitHub Desktop.
Save yinchunxiang/bc795abbb3a6d09ba39a1b87125f6c92 to your computer and use it in GitHub Desktop.
java configuration
package com.sophon.search;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Created by yinchunxiang on 05/06/2017.
*/
public class Config {
private Properties props = new Properties();
//public Config() {}
public boolean init(String file) {
try {
//InputStream in = Config.class.getResourceAsStream("search/config.properties");
System.out.println("file => " + file);
InputStream in = Config.class.getResourceAsStream(file);
if (null == in) {
System.out.println("input stream is null");
return false;
}
this.props.load(in);
in.close();
return true;
}catch (IOException e) {
System.out.println(e.toString());
return false;
}
}
public String get(String key) {
return this.props.getProperty(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment