打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JAVA读取Properties文档的两种常用方式
package com.wise;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
public class TestProperties {
 //the properties file 's name is test.properties,its filePath is the same as javaFile
//and the  content of the properties file is
// "i_am_key=i_am_value"
 public static void main(String[] args) {
  readPropertiesMethod1("/test.properties");
 }
 public static void readPropertiesMethod1(String filename){
  Properties pro = new Properties();
  try {
   InputStream is = TestProperties.class.getResourceAsStream("/test.properties");
   pro.load(is);
   String value = pro.getProperty("i_am_key");
   System.out.println(value);
  } catch (IOException e) {
   
  }
 }
 public static void readPropertiesMethod2(String filename){
  ResourceBundle rb = ResourceBundle.getBundle("test",Locale.getDefault());
  String value = rb.getString("i_am_key");
  System.out.println(value);
 }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用JAVA轻松操作properties文件
Java Properties 类读取配置文件信息
java对文件操作例子辅助类1
JAVA的国际化
Java常用类库(一)
Java中过滤敏感词
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服