Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java NIO The Glob mode Detailed     - OpenSSL for secure transmission and use of skills of files between Windows and Linux (Linux)

- Android custom title bar (Programming)

- C ++ implementation of the list of basic operations and test cases (Programming)

- Ten to improve the efficiency of the Linux bash tricks (Linux)

- Linux hybrid character device (Linux)

- JavaScript common functions summary (Programming)

- DRBD + Heartbeat solve NFS single point of failure (Server)

- OpenNMS separate database (Server)

- Build your own Web server under Ubuntu Linux system (Server)

- Ubuntu terminal command - see the port occupied and off (Linux)

- Linux file system structure Introduction (Linux)

- Linux Creating a new user error Creating mailbox file: File exists (Linux)

- xCAT deployment (Linux)

- How to migrate MySQL to MariaDB under linux (Database)

- Linux tool curl and wget advanced use (Linux)

- Fast Sort Algorithms (Programming)

- Seven kinds of DDoS attack methods and techniques Defensive (Linux)

- To install Ganglia configuration of experience under CentOS 5.5 (Linux)

- Linux screen command (Linux)

- Linux RHCS basic maintenance commands (Linux)

 
         
  Java NIO The Glob mode Detailed
     
  Add Date : 2017-08-31      
         
         
         
  One, what is the Glob?

In the program design, Glob is a pattern that uses wildcards to specify a file name. For example:. * Java is a simple Glob, which specifies all the extension "java" file. Glob patterns are widely used in the two wildcard "*" and "?." Wherein the asterisk means "any character or string of characters" and the question mark means "any single character."

Glob mode from the Unix operating system, Unix provides a "global order", which can be shortened to glob. Glob and regular expression pattern is similar, but its function is limited.

Two, Java NIO in Glob mode

Java SE7 the NIO libraries introduced Glob mode, which is used FileSystem class, using PathMatcher getPathMatcher (String syntaxAndPattern) method. Glob can be passed as arguments to PathMatcher. Similarly, in the Files Glob class can also be used to traverse the entire directory.

Three, Glob examples of Java NIO

Here is a Java program that uses the Glob pattern to search for the specified directory and its subdirectories.

package com.javapapers.java.nio;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
public class FileGlobNIO {
    public static void main (String args []) throws IOException {
        String glob = ". Glob: ** / * zip";
        String path = "D: /";
        match (glob, path);
    }
    public static void match (String glob, String location) throws IOException {
       
        final PathMatcher pathMatcher = FileSystems.getDefault (). getPathMatcher (
                glob);
       
        Files.walkFileTree (Paths.get (location), new SimpleFileVisitor < Path> () {
           
            @Override
            public FileVisitResult visitFile (Path path,
                    BasicFileAttributes attrs) throws IOException {
                if (pathMatcher.matches (path)) {
                    System.out.println (path);
                }
                return FileVisitResult.CONTINUE;
            }
            @Override
            public FileVisitResult visitFileFailed (Path file, IOException exc)
                    throws IOException {
                return FileVisitResult.CONTINUE;
            }
        });
    }
}

Program output is as follows:

D: \ AndroidLocation.zip
D: \ Eclipse \ 7dec2014 \ eclipse-jee-kepler-R-win32-x86_64 \ workspace \ .metadata \ .mylyn \ .tasks.xml.zip
D: \ Eclipse \ 7dec2014 \ eclipse-jee-kepler-R-win32-x86_64 \ workspace \ .metadata \ .mylyn \ repositories.xml.zip
D: \ Eclipse \ 7dec2014 \ eclipse-jee-kepler-R-win32-x86_64 \ workspace \ .metadata \ .mylyn \ tasks.xml.zip
D: \ mysql-workbench-community-6.2.5-winx64-noinstall.zip
D: \ workspace \ Android \ AndroidChatBubbles-master.zip
D: \ workspace \ Android \ Google Chat \ XMPPChatDemo.zip
D: \ workspace \ Android \ Update-Android-UI-from-a-Service-master.zip
D: \ workspace \ Android Chat \ AndroidDialog.zip
D: \ workspace \ Android Wear \ AndroidWearPreview.zip
     
         
         
         
  More:      
 
- How to install Nginx on FreeBSD 10.2 as an Apache reverse proxy (Server)
- Experience PHP 7.0 on CentOS 7.x / Fedora 21 (Server)
- C ++ Supplements - Virtual Function Principle (Programming)
- Linux System Tutorial: Fix ImportError: No module named wxversion error (Linux)
- Upload the project to GitHub, synchronous remote repository Github (Linux)
- C ++ virtual functions Classic Insights (Programming)
- Eclipse improve the efficiency of good habits (Programming)
- Single-node Hadoop environment to build (Server)
- ORA-30926 and MERGE tables empty the temporary occupation problem (Database)
- RHEL5.x RHEL6.x replace CentOS yum source (Linux)
- To install and deploy Apache under the CentOS (Server)
- C ++ string in the end (Programming)
- Linux-based Heartbeat high availability configuration httpd service (Server)
- Java abstract class instantiation (Programming)
- What is Unikernel? (Linux)
- To create a file in Linux directory by setfacl (Linux)
- Nginx installation configuration Zabbix (Server)
- CentOS 6.x and CentOS7 installation RPMforge (Linux)
- Matters Oracle 11.2 single instance when connecting ASM need to pay attention and deal with the problem (Database)
- Zabbix monitoring of the switch (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.