import java.io.*;
import java.util.*;public class Test{
public static void main(String[] args) throws Exception{
Vector v = new Vector();
File f = new File("E:/web/bologu/new");//文件夹路径
if(f.isDirectory()) {
String[] str = null;
str = f.list();
for(int i = 0 ; i < str.length ; i ++){
String s = str[i];
if(s.indexOf("java") != -1)
v.add(str[i]);
}
}
System.out.println(v);//所包含的文件名
}
}
import java.util.*;public class Test{
public static void main(String[] args) throws Exception{
Vector v = new Vector();
File f = new File("E:/web/bologu/new");//文件夹路径
if(f.isDirectory()) {
String[] str = null;
str = f.list();
for(int i = 0 ; i < str.length ; i ++){
String s = str[i];
if(s.indexOf("java") != -1)
v.add(str[i]);
}
}
System.out.println(v);//所包含的文件名
}
}
不是文件名中包含,而是文件内容中包含.
txt你直接全文搜索就可以了