日期:2014-05-20  浏览次数:20622 次

java正则表达式的一个小问题
本帖最后由 wo111180611 于 2013-04-27 01:24:51 编辑
public class moveFile {

private static String oldPath = null;

public static void main(String[] args) {
oldPath = "D:\\迅雷下载";
findFile(oldPath);
}

public static void findFile(String path) {
File f = new File(path);
File[] fileNames = f.listFiles();

for (File child : fileNames) {
if (child.getName().matches("^jia"))
System.out.println(child.getName());
}
}
}

文件夹下面有以“jia” 开头的文件 为什么不输出呢

------解决方案--------------------
if (child.getName().matches("^jia.*"))
------解决方案--------------------
对于^这个符号应该与【】组合使用。
[^abc] 任何字符,除了 a、b 或 c(否定)