【Java-파일】디렉토리생성

【Java-파일】디렉토리생성

1. 설명

이 포스트에서 다루는 예제는 디렉토리를 생성하는 코드입니다.

2. 소스코드

- 메서드

public boolean makeDir(String path) { File f = new File(path); if ( f.exists() ) { return true; // 이미 존재하면 다시 생성할 필요는 없음 } return new File(path).mkdirs(); }

- 메인

public class File_05_MakeDir { public static void main(String[] args) { try { for (String str : args ) { System.out.println("Param : "+str); } String path = args[0]; FileUtil fu = new FileUtil(); System.out.println("Case 1 : "+ fu.makeDir(path)); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }

3. 실행결과【Windows(이클립스) / Linux】

4. 전체코드

https://github.com/leeyoungseung/template-java

from http://koiking.tistory.com/30 by ccl(A) rewrite - 2021-09-12 09:27:26