Spring服务的文件服务使用类是:
org.springframework.core.io.support.PathMatchingResourcePatternResolver
源码:
package test;
import java.io.IOException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
public class SpringFilePathTest {
public static void main(String[] args) {
PathMatchingResourcePatternResolver pathPattern = new PathMatchingResourcePatternResolver();
try {
Resource[] ress = pathPattern
.getResources("file:D:/**/npp.4.3.bin/**.xml");
for (Resource res : ress) {
System.out.println(res.getFile().getAbsolutePath());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
运行结果:
log4j:WARN No appenders could be found for logger
(org.springframework.core.io.support.PathMatchingResourcePatternResolver).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
D:\greensoft\npp.4.3.bin\config.xml
D:\greensoft\npp.4.3.bin\contextMenu.xml
D:\greensoft\npp.4.3.bin\doLocalConf.xml
D:\greensoft\npp.4.3.bin\langs.xml
D:\greensoft\npp.4.3.bin\session.xml
D:\greensoft\npp.4.3.bin\shortcuts.xml
D:\greensoft\npp.4.3.bin\stylers.xml
以上在Spring 3.05、3.10版本测试通过。
如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。