프로젝트 프로필 xml,ini,porpertys 솔 루 션
Configuration 은 다음 과 같은 유형의 파일 을 조작 할 수 있 습 니 다.Properties files XML documens Windows INI files Properties list files(plist)JNDI JDBC Datasource System properties Applet parameters Servlet parameters
좋아,지금부터 하 자.
우선 apache 의 comons 안에 있 는 세 개의 가방 을 사용 해 야 합 니 다.
각각 commons-collections-3.2.1,commons-lang-2.4,commons-configuration-1.5.jar
apache 공식 에 가서 이 세 개의 가방 을 다운로드 하 십시오.앞의 두 개가 없 으 면 이상 한 오류 가 발생 할 수 있 습 니 다.
사용 이 아주 간단 합 니 다.
우선 루트 디 렉 터 리 에 xml 프로필 을 만 듭 니 다.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : XMLtest.xml.xml
Created on : 2008 9 15 , 9:08
Author : Administrator
Description:
Purpose of the document follows.
-->
<gui-definition>
<colors>
<background>#808080</background>
<text>#000000</text>
<header>#008000</header>
<link normal="#000080" visited="#800080"/>
<default>${colors.header}</default>
</colors>
<rowsPerPage>15</rowsPerPage>
<buttons>
<name>OK,Cancel,Help</name>
<name>Yes,No,Cancel</name>
</buttons>
<numberFormat pattern="###\,###.##"/>
</gui-definition>
우선 자원 파일 로드
XMLConfiguration config = new XMLConfiguration();
config.setDelimiterParsingDisabled(true);
config.setFileName("XMLtest.xml");
config.load();
읽 기 진행
List<String> buttons = config.getList("buttons.name");
for (String button : buttons) {
System.out.println(button);
}
사실 사용 은 config.get 데이터 형식 입 니 다.예 를 들 어 config.getString,config.getDouble 등 편리 함 을 얻 을 수 있 습 니 다.
설정 파일 의 내용 이 바 뀌 었 을 때 Commons Configuration 은 설정 파일 의 내용 을 자동 으로 다시 읽 을 수 있 는 특수 한 기능 도 있 습 니 다.
사용 방법XMLConfiguration config = new XMLConfiguration(filename);
config.setReloadingStrategy(new FileChangedReloadingStrategy());
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 파일 압축 및 압축 풀기파일 의 간단 한 압축 과 압축 해 제 를 실현 하 였 다.주요 테스트 용 에는 급 하 게 쓸 수 있 는 부분 이 있 으 니 불편 한 점 이 있 으 면 아낌없이 가르쳐 주 십시오. 1. 중국어 문 제 를 해 결 했 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.