산출물 작업 시 파일 정의서를 작성할 때 유용하게 사용할 수 있다. ㅋ

import java.io.File;

public class Test {

    public static void main(String[] args) {
        File dir = new File("D:\\test");
       
        File[] fileList = dir.listFiles();
       
        new Test().printFiles(fileList);
    } 

   public String getFileExtension(String fileName) {
        return fileName.substring(fileName.lastIndexOf(".")+1, fileName.length());
    }
   
    public void printFiles(File[] fileList){
       
        for(int i = 0;i<fileList.length;i++) {
            if(fileList[i].isDirectory()) {
                printFiles(fileList[i].listFiles());
            } else {
                if(getFileExtension(fileList[i].getName()).equals("java")
                        || getFileExtension(fileList[i].getName()).equals("xml")
                        || getFileExtension(fileList[i].getName()).equals("properties") ) {
                    System.out.println(fileList[i].getPath());
                }
            }       
        }
    }
}

'java > util' 카테고리의 다른 글

[정규식] - 핸드폰 번호 포맷 변경  (0) 2013.01.02
[util] - 자바 문자열 압축/압축풀기  (0) 2011.11.14
[InputStream] - String to InputStream  (1) 2010.10.13
[util] - byte to hex string  (0) 2010.09.07
[java] - replaceNull  (0) 2010.07.05
Posted by 짱가쟁이