GGYU

디렉토리 조회 본문

프로그래밍/JAVA

디렉토리 조회

GANADARA 2018. 7. 19. 21:21

public void subDirList(String source){

File dir = new File(source); 

File[] fileList = dir.listFiles(); 

try{

for(int i = 0 ; i < fileList.length ; i++){

File file = fileList[i]; 

if(file.isFile()){

    // 파일이 있다면 파일 이름 출력

System.out.println("\t 파일 이름 = " + file.getName());

}else if(file.isDirectory()){

System.out.println("디렉토리 이름 = " + file.getName());

    // 서브디렉토리가 존재하면 재귀적 방법으로 다시 탐색

subDirList(file.getCanonicalPath().toString()); 

}

}

}catch(IOException e){

}

}

'프로그래밍 > JAVA' 카테고리의 다른 글

thread 사용법  (0) 2018.07.19
threadpool 사용법  (0) 2018.07.19
Input/OutputStream  (0) 2018.07.19
BufferedReader/Writer 사용법  (0) 2018.07.19
LineNumberReader 사용법  (0) 2018.07.19
Comments