When i run the following, i get this error message:
FileList.java:21: non-static method searchDir(java.io.File,java.lang.String) can
not be referenced from a static context
matching = searchDir(curDir, search);
^
Thanks for any help. Here is the code:
FileList.java:21: non-static method searchDir(java.io.File,java.lang.String) can
not be referenced from a static context
matching = searchDir(curDir, search);
^
Thanks for any help. Here is the code:
Code:
import java.io.File;
import java.util.*;
public class FileList {
public static void main(String args[]) {
File curDir = new File("C:/");
byte b[] = new byte[100];
String search;
String s[];
Vector matching;
System.out.print("Please enter your search criteria: ");
// get your input
System.in.read(b);
// decode the byte array
search = new String(b);
matching = searchDir(curDir, search);
// to get the values in the Vector
s = new String[matching.size()];
System.out.println("Matching results:");
for(int i=0; i < matching.size(); i++) {
s[i] = (String)matching.elementAt(i);
System.out.println(s[i]);
// you don't really need the s[], you could also do this
// System.out.println(matching.elementAt(i));
}
}
public Vector searchDir(File curDir, String searchText){
Vector matching = new Vector();
File[] allFiles = curDir.listFiles();
for(int c=0; c < allFiles.length; c++) {
if (allFiles[c].isFile()) {
// this will match any file that contains the searchText
if (allFiles[c].getName().indexOf(searchText) >= 0)
matching.addElement(allFiles[c].getName());
}
}
return matching;
}
}