2009년 7월 2일 목요일

File list

=filelist(new File("."));

public Vector filelist(File here) {
File[] rootFileList = here.listFiles();
Vector<String> filelist=new Vector<String>();
for (int i = 0; i < rootFileList.length; i++) {
if (!rootFileList[i].isDirectory()) {
String filename = rootFileList[i].getName();
String ext = filename.substring(filename.lastIndexOf("."),filename.length());
if (ext.equalsIgnoreCase(".gif") || ext.equalsIgnoreCase(".jpg")) {
filelist.addElement(filename);
System.out.println(filename);
}
}
}
return filelist;
}
public void searchDirectory(File here) {
File[] rootFileList = here.listFiles();
for (int i = 0; i < rootFileList.length; i++) {
if (rootFileList[i].isDirectory()) {
searchDirectory(rootFileList[i]);
} else {
try {
String filename = rootFileList[i].getName();
String ext = filename.substring(filename.lastIndexOf("."),filename.length());
if (!ext.equalsIgnoreCase(".gif")&& !ext.equalsIgnoreCase(".jpg")) {
System.out.println(rootFileList[i].toURL());
} else {
System.out.println(ext+"<img>");
}
} catch (Exception e) {
}
}
}
}

댓글 없음:

댓글 쓰기