메모를 폴더로 정리하기
정리를 위해 앱은 메모를 전용 폴더에 저장해야 해요. 이 연습에서는 "notes"라는 디렉터리를 만들고 그 경로를 출력해 보겠습니다. 이렇게 하면 관련 파일을 한곳에 모아 두고 쉽게 찾을 수 있어요.
이 연습은 강의의 일부입니다
Java의 입력/출력과 스트림
연습 안내
notes를 가리키는File객체notesDir을(를) 생성하세요.- 시스템에
notes라는 이름의 디렉터리를 생성하세요. notes디렉터리의 상대 경로를 가져오세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
class DirectoryManager {
public static void main(String[] args) {
try {
// Create a File object to represent the directory
File notesDir = ____ _____("notes");
// Create a directory in the system
if (____.____()) {
System.out.println("Directory 'notes' created successfully");
}
// Retrieve and print the relative path of the directory
System.out.println("Relative Path: " + ____.____());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}