1 23 24 29 30 package com.sun.enterprise.util.io; 31 import java.io.*; 32 import java.util.*; 33 34 39 public abstract class FileLister 40 { 41 FileLister(File root) 42 { 43 mainRoot = root; 44 fileList = new ArrayList(); 45 } 46 47 abstract protected boolean relativePath(); 48 49 public String [] getFiles() 50 { 51 getFilesInternal(mainRoot); 52 String [] files = new String [fileList.size()]; 53 54 if(files.length <= 0) 55 return files; 56 57 int len = 0; 58 59 if(relativePath()) 60 len = mainRoot.getPath().length() + 1; 61 62 for(int i = 0; i < files.length; i++) 63 { 64 files[i] = ((File)fileList.get(i)).getPath().substring(len).replace('\\', '/'); 65 } 66 67 Arrays.sort(files, String.CASE_INSENSITIVE_ORDER); 68 return files; 69 } 70 71 72 public void getFilesInternal(File root) 73 { 74 File[] files = root.listFiles(); 75 76 for(int i = 0; i < files.length; i++) 77 { 78 if(files[i].isDirectory()) 79 { 80 getFilesInternal(files[i]); 81 } 82 else 83 fileList.add(files[i]); } 85 } 86 87 88 89 90 91 92 93 private ArrayList fileList = null; 94 private File mainRoot = null; 95 } 96 97 98 99 | Popular Tags |