자바 기반 사용자 정의 프로필 읽 기 및 참조

우선 resources 디 렉 터 리 에 사용자 정의 프로필 을 만 듭 니 다.

프로필 형식:

도구 클래스 를 작성 하여 설정 파 라 메 터 를 얻 습 니 다.

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class MyConfig {
  public static Properties myProp = new Properties();
  public static InputStream myResource = MyConfig.class.getResourceAsStream("/myConfig.properties");
  static {
    try {
      myProp.load(myResource);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public String getMyConf(String props) {
    return myProp.getProperty(props);
  }
  
  public static void main(String[] args) {
    final MyConfig myConfig = new MyConfig();
    System.out.println(myConfig.getMyConf("master_ip"));
  }
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기