File file =
new
File(
"a.txt"
);
//判断后缀
if
(file.getName().endsWith(
".txt"
)) {
System.out.println(
"是txt文件"
);
}
//判断前缀
if
(file.getName().startWith(
"2012-"
)) {
System.out.println(
"是2012年的文件"
);
}