Java 代码读取properties文件
jdk1.6
package read;
import java.io.file;
import java.io.fileinputstream;
import java.io.ioexception;
import java.io.inputstreamreader;
import java.util.properties;
public class fileread {
public static void main(string[] args) {
fileread re=new fileread();
string x=re.gete();
system.out.println(x);
}
public string gete(){
properties props = new properties();
system.out.println(new file("").getabsolutepath());
try {
props.load(new inputstreamreader(new fileinputstream(new file("").getabsolutepath()+"/src/config/read.properties"), "utf-8"));
} catch (ioexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
string isuse = props.getproperty("isuse");
return isuse;
}
}
jdk1.7及以上
import java.io.inputstream;
import java.util.properties;
properties pro = new properties();
try(inputstream is = getclass().getresourceasstream(
"/config/multi-language-configuration.properties")) {
pro.load(is);
} catch (exception e) {
}
string isuse = pro.getproperty("isuse");