【发布时间】:2018-05-15 10:02:33
【问题描述】:
我的控制器方法(它有一个列出文件的方法,从 JSP 上的属性文件中提到的路径)
private String[] getFileListing(String servers) throws IOException {
Properties prop = new Properties();
String propFileName = "config.properties";
InputStream input = getClass().getClassLoader().getResourceAsStream(propFileName);
prop.load(input);
if (servers.equals("MS1")) {
File f = new File(prop.getProperty("path.MS1"));
String[] list = f.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".txt")||name.endsWith(".log");
}
});
return list;
} else {
File f = new File(prop.getProperty("path.MS2"));
String[] list = f.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".txt")||name.endsWith(".log");
}
});
return list;
}
}
我想显示带有常见扩展名的日志文件,例如 - .txt 或 .log 但系统也会创建扩展名为 .1 .2 .3 的文件。
- 是否有明确的方法来包含所有这些文件类型扩展名?
- 如果不是,那么如何显示目录中“排除”某些文件类型的所有文件。 (我想从目录中排除一些其他系统生成的文件)。
谢谢!
【问题讨论】:
-
要排除文件类型,为什么不直接使用
!name.toLowerCase().endsWith("...")?