org.apache.commons.io.filefilter

Class SymbolicLinkFileFilter

  • All Implemented Interfaces:
    FileFilter, FilenameFilter, Serializable, FileVisitor< Path>, PathFilter, PathVisitor, IOFileFilter

    public class SymbolicLinkFileFilter
    extends AbstractFileFilter
    implements Serializable
    This filter accepts Files that are symbolic links.

    For example, here is how to print out a list of the real files within the current directory:

    Using Classic IO

     File dir = new File(".");
     String[] files = dir.list(SymbolicLinkFileFilter.INSTANCE);
     for (String file : files) {
         System.out.println(file);
     }
     

    Using NIO

     final Path dir = Paths.get("");
     final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.FILE);
     //
     // Walk one dir
     Files.walkFileTree(dir, Collections.emptySet(), 1, visitor);
     System.out.println(visitor.getPathCounters());
     System.out.println(visitor.getFileList());
     //
     visitor.getPathCounters().reset();
     //
     // Walk dir tree
     Files.walkFileTree(dir, visitor);
     System.out.println(visitor.getPathCounters());
     System.out.println(visitor.getDirList());
     System.out.println(visitor.getFileList());
     
    Since:
    2.11.0
    See Also:
    FileFilterUtils.fileFileFilter(), Serialized Form
    • Field Detail

    • Constructor Detail

      • SymbolicLinkFileFilter

        protected SymbolicLinkFileFilter()
        Restrictive constructor.

Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.