◆ 무한한 가능성/& JAVA

JAVA ini 파일 읽고 쓰기

치로로 2016. 3. 17. 10:36

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);
  }
 }
}


http://pyoungon.tistory.com/22