1 17 18 package org.objectweb.jac.util; 19 20 import java.io.FilenameFilter ; 21 import java.io.IOException ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 29 public class File extends java.io.File { 30 public File(java.io.File file) { 31 this(file.getPath()); 32 } 33 public File(String pathname) { 34 super(Files.expandFileName(pathname)); 35 } 36 public File(File parent, String child) { 37 this(parent.getPath(),child); 38 } 39 public File(java.io.File parent, String child) { 40 this(parent.getPath(),child); 41 } 42 public File(String parent, String child) { 43 super(Files.expandFileName(parent),child); 44 } 45 46 52 public List listFilesRecursively(FilenameFilter filter) { 53 LinkedList files = new LinkedList (); 54 listFilesRecursively(filter,files); 55 return files; 56 } 57 58 64 public void listFilesRecursively(FilenameFilter filter, List files) { 65 String [] names = list(); 66 if(names==null) return; 67 for (int i=0; i<names.length; i++) { 68 File file = new File(this,names[i]); 69 if (filter.accept(this,names[i])) 70 files.add(file); 71 if (file.isDirectory()) 72 file.listFilesRecursively(filter,files); 73 } 74 } 75 76 83 public String getRelativePath(File parent) throws IOException { 84 String parentPath = parent.getCanonicalPath(); 85 String path = getCanonicalPath(); 86 if (path.startsWith(parentPath)) { 87 return path.substring(parentPath.length()+1); 88 } else { 89 return getPath(); 90 } 91 } 92 93 public java.io.File [] listDirectories() { 94 return listFiles(Files.directoryFilter); 95 } 96 97 public java.io.File [] listNonHiddenFiles() { 98 return listFiles(Files.nonHiddenFilter); 99 } 100 } 101 102 | Popular Tags |