Language/Java / JSP
[Java] 디렉토리내 특정 파일 리스트 출력
과일가게 개발자
2014. 7. 28. 13:13
반응형
디렉토리에서 파일이름이 특정 패턴으로 된 파일들 찾아내기
File path = new File("C:\test\"); final String fatternName = "TEMP" ; String fileList[] = path.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.startsWith(fatternName); // TEMP로 시작하는 파일들만 return } }); // 파일리스트 출력 if(fileList.length > 0){ for(int i=0; i < fileList.length; i++){ System.out.println(fileList[i]) ; } }
Tip) 디렉토리의 파일 전체 목록을 가져오는것은 아래와 같이도 가능하다.
File path = new File("C:\test\") ;File[] list = path.listFiles() ;