- Properties 클래스
Properties 클래스
1. HashTable 클래스의 하위 클래스(Map 클래스)
2. (key<String>,value<String>) 쌍인 객체로 저장.
=> 제네릭 표현 안함
(이유. key든 value든 String이여서 굳이 제네릭 표현을 할 필요가 없다.)
3. FileInputStream 에서 Properties 형태의 내용을 Map객체로 load 할 수 있음.
📌
package chap14;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesEx1 {
public static void main(String[] args) throws IOException {
Properties pr = new Properties();
System.out.println(pr);
//a.properties : chap14 프로젝트 폴더에 생성
FileInputStream fis = new FileInputStream("a.properties");
pr.load(fis); //a.properties 파일의 내용을 Properties 객체의 요소로 저장
pr.put("addr", "서울");
System.out.println(pr);
System.out.println(pr.get("name"));//홍길동
System.out.println(pr.get("tel"));//1234
}
}
'수업(국비지원) > Java' 카테고리의 다른 글
[Java] chap14 : IO기반 입출력 - File 클래스, File 클래스의 주요 메서드 (0) | 2023.04.17 |
---|---|
[Java] chap14 : IO기반 입출력 - IO Exam1. (0) | 2023.04.17 |
[Java] chap14 : IO기반 입출력 - FileWriter 클래스 (0) | 2023.04.17 |
[Java] chap14 : IO기반 입출력 - FileOutputStream 클래스 (0) | 2023.04.17 |
[Java] chap14 : IO기반 입출력 - FileReader 클래스 (0) | 2023.04.17 |