1.Maven项目 -> resource目录右击 -> Resource Bundlechua ->创建name.properties文件
2.输入内容
name=XIAOLIANG
3.代码中引用(注意此处文件名前需要加上/ 表示根目录,不然获取不到,is为null)
public class Test { public static void main(String[] args) throws IOException { InputStream is = Test.class.getResourceAsStream("/name.properties"); Properties properties = new Properties(); properties.load(is); System.out.println( properties.getProperty("name")); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)