자바에서 폴더는 어떻게 만드나요?
조회수 2670회
1 답변
-
File theDir = new File("새 폴더"); // 해당 디렉토리가 없을경우 디렉토리를 생성한다. if (!theDir.exists()) { System.out.println("creating directory: " + directoryName); boolean result = false; try{ theDir.mkdir(); result = true; } catch(SecurityException se){ //handle it } if(result) { System.out.println("DIR created"); } }
이렇게 하시면 됩니다.
- exists() 만 체크하는 것 보다 '새 폴더'가 디렉토리가 아니라 파일일 경우엔 Exception을 던져주면 더 좋을 것 같습니다. 알 수 없는 사용자 2016.2.1 18:16
댓글 입력