a.properties文件内容
usename=殿堂之路
passwords=清华大学城
java代码::
package p;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PRO {
private static Properties pro = new Properties();
public static void main(String[] args) {
InputStream in = new PRO().getClass().getClassLoader().getResourceAsStream("p/a.properties"); //路径
try {
pro.load(in);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("出错了!!");
}
System.out.println("姓名:"+pro.getProperty("passwords")+"=================="+pro.getProperty("usename"));
System.out.println("密码:"+pro.getProperty("usename"));
System.out.println("没有内容时"+pro.getProperty("none", "1223"));//没有内容时会显示第二个参数,即“1223”
}
}