Java 에서 *.ini 파일을 읽고 쓰는 방법은 java.util.Properties 를 이용하면 된다.
java.util.Properties 사용 시 한글 깨짐 처리는 아래 링크에서 해결할 수 있다.
사용방법은 아래의 소스를 참고하고 자세한 사항은 Java 도움말을 참조하면 된다.
- load() : ini 파일 읽기
- store() : ini 파일 쓰기
- getProperty() : key 값 읽기
- setProperty() : key 값 저장
java.util.Properties 사용 시 한글 깨짐 처리는 아래 링크에서 해결할 수 있다.
import java.util.*; import java.io.*; class ExProperties { public static void main(String args[]) { ExProperties ini = new ExProperties(); ini.doit(); } public void doit() { try{ Properties p = new Properties(); // ini 파일 읽기 p.load(new FileInputStream("user.ini")); // Key 값 읽기 System.out.println("user = " + p.getProperty("DBuser")); System.out.println("password = " + p.getProperty("DBpassword")); System.out.println("location = " + p.getProperty("DBlocation")); // Key 값 저장 p.setProperty("Key", p.getProperty("DBuser" )); p.list(System.out); // ini 파일 쓰기 p.store( new FileOutputStream("user.ini"), "done."); } catch (Exception e) { System.out.println(e); } } }
'컴퓨터 > Java' 카테고리의 다른 글
RIA 개발 도구 - Google Web Toolkit (0) | 2011.04.09 |
---|---|
Java 개발 환경 구성(Eclipse, Plug-in 설치) (0) | 2011.04.07 |
Java SE / EE / ME 비교 (0) | 2011.01.22 |
Java Profiling (0) | 2011.01.17 |
Java 에서 Logging 처리 (0) | 2011.01.17 |