Programming/Java
자바 디렉토리 내 특정 파일 리스트 출력 / 디렉토리 전체 목록 가져오기
배고프당
2019. 4. 3. 08:50
728x90
1. 디렉토리 파일 특정 패턴으로 된 목록만 가져오기
File path = new File("D:/workspace_example/Data/");
final String pattern = "2019" ;
String fileList[] = path.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(pattern); // pattern 형식으로 시작하는(여기서는 2019로 시작하는 이름)
}
});
// file list 출력
if(fileList.length > 0){
for(int i=0; i < fileList.length; i++){
System.out.println(fileList[i]) ;
}
}
2. 디렉토리 파일 전체 목록 가져오기
File path = new File("D:/workspace_example/Data/");
File[] fileList = path.listFiles();
if(fileList.length > 0){
for(int i=0; i < fileList.length; i++){
System.out.println(fileList[i]) ;
}
}
728x90