2.3.1 search for files in projects and 2.3.1 search for files in projects

Source: Internet
Author: User

2.3.1 search for files in projects and 2.3.1 search for files in projects

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;/** search for files in the directory: filter all files in the dir project using pattern matching. properties file; * @ author jinxing * @ DirectoryStream <Path> stream = Files. newDirectoryStream (dir ,"*. properties ") * The pattern matching used in the filter stream is called glob pattern matching --*. properties */public class PathFindGlob {public static void main (String [] args) {// The pre-prepared directory and the three files in it: log4j. xml, signed URL. properties, weixinjsapi. properties 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.