단순화된 데이터 기술 형식
XML 파일을 읽고, 쓰기 위한 IO 관련 클래스 필요한데..! Properties 컬렉션 객체가 필요하다.
- Map 후손 클래스
- Key, Value 모두 String(문자열)
- XML 파일을 읽고, 쓰는데 특화된 메서드 제공
👩💻 그렇다면 xml 파일을 생성해보자!
try {
Scanner sc = new Scanner(System.in);
// ✔ Properties 객체 생성
Properties prop = new Properties();
System.out.print("생성할 파일 이름 : ");
String fileName = sc.next();
// ✔ FileOutputStream 생성
FileOutputStream fos = new FileOutputStream(fileName + ".xml");
// ✔ Properties 객체를 이용해서 XML 파일 생성
prop.storeToXML(fos, ".xml file!!!");
System.out.println(fileName+ ".xml 파일 생성 완료");
}catch (Exception e) {
e.printStackTrace();
}
➡ XML file 생성 시 Exception이 발생하기에 try~catch문 안에 작성해주면 된다! 🙋♀️