星空网 > 软件开发 > Java

2.3.1 在项目中查找文件

Demo:

import java.io.IOException;import java.nio.file.DirectoryStream;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;/**在目录中查找文件:用模式匹配过滤dir项目中所有的.properties文件; * @author jinxing * @DirectoryStream DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.properties") * 过滤流中用到的模式匹配称为glob模式匹配——*.properties */public class PathFindGlob {    public static void main(String[] args) {        // 提前准备好的目录及其中的三个文件:log4j.    Path dir = Paths.get("/Users/jinxing/Documents/pathtest/path1");        try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.properties")) {            for (Path entry: stream) {        System.out.println(entry.getFileName());      }          } catch (IOException e) {      System.out.println(e.getMessage());    }      }}

Ran As Java Application:

shortUrl.propertiesweixinjsapi.properties

 




原标题:2.3.1 在项目中查找文件

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

奥士达国际物流:https://www.goluckyvip.com/tag/101069.html
BuzzSumo:https://www.goluckyvip.com/tag/10107.html
国际物流价格表:https://www.goluckyvip.com/tag/101070.html
墨西哥国际货运:https://www.goluckyvip.com/tag/101071.html
国际货运墨西哥:https://www.goluckyvip.com/tag/101072.html
物流国际货运物流:https://www.goluckyvip.com/tag/101073.html
洛阳市涧西区有啥好玩的地方 洛阳涧西区附近景点:https://www.vstour.cn/a/408256.html
九月初新疆旅游服装搭配(新疆游玩必备衣服清单):https://www.vstour.cn/a/408257.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流