Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list(FilenameFilter filter) 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:Main.java

public static void main(String[] args) {
    final String dir = "C:\\data\\projects\\";
    final String pattern = ".pdf";
    final File file = Paths.get(dir).toFile();

    Stream.of(file.list((pFile, pString) -> pString.endsWith(pattern))).forEach(System.out::println);
    ;/*w ww  .j a v a 2 s  . c  o  m*/
}

From source file:DirListOnly.java

public static void main(String args[]) {
    String dirname = "/java";
    File f1 = new File(dirname);
    FilenameFilter only = new OnlyExt("html");
    String s[] = f1.list(only);

    for (int i = 0; i < s.length; i++) {
        System.out.println(s[i]);
    }//  w ww .  j a  v a  2s. co m
}

From source file:ExtensionFilter.java

public static void main(String args[]) {
    String dirname = "/java";
    File f1 = new File(dirname);
    FilenameFilter only = new ExtensionFilter("html");
    String s[] = f1.list(only);
    for (int i = 0; i < s.length; i++) {
        System.out.println(s[i]);
    }/*from   ww w  .j  a v  a 2  s. c  o  m*/
}

From source file:edu.cornell.med.icb.goby.util.RenameWeights.java

public static void main(final String[] args) throws IOException {
    final File directory = new File(".");

    final String[] list = directory.list(new FilenameFilter() {
        public boolean accept(final File directory, final String filename) {

            final String extension = FilenameUtils.getExtension(filename);
            return (extension.equals("entries"));
        }/*from  w w w  . j  a  v  a 2  s .  c o m*/
    });
    for (final String filename : args) {
        final String extension = FilenameUtils.getExtension(filename);
        final String basename = FilenameUtils.removeExtension(filename);
        for (final String alignFilename : list) {
            final String alignBasename = FilenameUtils.removeExtension(alignFilename);
            if (alignBasename.endsWith(basename)) {
                System.out.println("move " + filename + " to " + alignBasename + "." + extension);

                final File destination = new File(alignBasename + "." + extension);
                FileUtils.deleteQuietly(destination);
                FileUtils.moveFile(new File(filename), destination);
            }
        }

    }
}

From source file:Main.java

public static void main(String[] args) {

    File f = new File("c:/test");

    FilenameFilter filter = new MainFilenameFilter("txt");

    // array of files and directory
    String[] paths = f.list(filter);

    // for each name in the path array
    for (String path : paths) {
        System.out.println(path);
    }//from   w w w.j  av  a  2 s .co  m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File dir = new File("c:\\temp");
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return !name.startsWith(".");
        }/*from  w ww.j  a v  a2 s .co m*/
    };
    String[] children = dir.list(filter);

}

From source file:net.itransformers.idiscover.discoverylisteners.XmlTopologyDeviceLogger.java

public static void main(String[] args) throws IOException, JAXBException {
    String path = "devices_and_models\\lab\\undirected";
    File dir = new File(path);
    String[] files = dir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".hml"));
        }/*w  w w . j a va 2 s .c  om*/
    });
    Map<String, String> params = new HashMap<String, String>();
    params.put("path", path);
    params.put("conf/xslt", "iDiscover\\conf\\xslt\\transformator3.xslt");
    XmlTopologyDeviceLogger logger = new XmlTopologyDeviceLogger(params, null, null);

    for (String fileName : files) {
        FileInputStream is = new FileInputStream(path + File.separator + fileName);
        DiscoveredDeviceData discoveredDeviceData;
        try {
            discoveredDeviceData = JaxbMarshalar.unmarshal(DiscoveredDeviceData.class, is);
        } finally {
            is.close();
        }
        String deviceName = fileName.substring("device-".length(), fileName.length() - ".xml".length());
        logger.handleDevice(deviceName, null, discoveredDeviceData, null);
    }

}

From source file:net.itransformers.idiscover.discoverylisteners.TopologyDeviceLogger.java

public static void main(String[] args) throws FileNotFoundException, JAXBException {
    String path = "tmp1";
    File dir = new File(path);
    String[] files = dir.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (name.startsWith("device") && name.endsWith(".xml"));
        }/*from w w w . j  ava2 s  .c om*/
    });
    TopologyDeviceLogger logger = new TopologyDeviceLogger(path);
    String host = "10.33.0.5";
    String snmpROComm = "public";
    Map<String, String> resourceParams = new HashMap<String, String>();
    resourceParams.put("community", snmpROComm);
    resourceParams.put("version", "1");
    Resource resource = new Resource(host, null, resourceParams);

    for (String fileName : files) {
        FileInputStream is = new FileInputStream(path + File.separator + fileName);
        DiscoveredDeviceData discoveredDeviceData = null;
        try {
            discoveredDeviceData = JaxbMarshalar.unmarshal(DiscoveredDeviceData.class, is);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        String deviceName = fileName.substring("device-".length(), fileName.length() - ".xml".length());
        logger.handleDevice(deviceName, null, discoveredDeviceData, resource);
    }

}

From source file:enrichment.Disambiguate.java

/**prerequisites:
 * cd silk_2.5.3/*_links//w w  w  . j ava2 s  . com
 * cat *.nt|sort  -t' ' -k3   > $filename
 * 
 * @param args $filename
 * @throws IOException
 * @throws URISyntaxException
 */
public static void main(String[] args) {
    File file = new File(args[0]);
    if (file.isDirectory()) {
        args = file.list(new OnlyExtFilenameFilter("nt"));
    }

    BufferedReader in;
    for (int q = 0; q < args.length; q++) {
        String filename = null;
        if (file.isDirectory()) {
            filename = file.getPath() + File.separator + args[q];
        } else {
            filename = args[q];
        }
        try {
            FileWriter output = new FileWriter(filename + "_disambiguated.nt");
            String prefix = "@prefix rdrel: <http://rdvocab.info/RDARelationshipsWEMI/> .\n"
                    + "@prefix dbpedia:    <http://de.dbpedia.org/resource/> .\n"
                    + "@prefix frbr:   <http://purl.org/vocab/frbr/core#> .\n"
                    + "@prefix lobid: <http://lobid.org/resource/> .\n"
                    + "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"
                    + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n"
                    + "@prefix mo: <http://purl.org/ontology/mo/> .\n"
                    + "@prefix wikipedia: <https://de.wikipedia.org/wiki/> .";
            output.append(prefix + "\n\n");
            in = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));

            HashMap<String, HashMap<String, ArrayList<String>>> hm = new HashMap<String, HashMap<String, ArrayList<String>>>();
            String s;
            HashMap<String, ArrayList<String>> hmLobid = new HashMap<String, ArrayList<String>>();
            Stack<String> old_object = new Stack<String>();

            while ((s = in.readLine()) != null) {
                String[] triples = s.split(" ");
                String object = triples[2].substring(1, triples[2].length() - 1);
                if (old_object.size() > 0 && !old_object.firstElement().equals(object)) {
                    hmLobid = new HashMap<String, ArrayList<String>>();
                    old_object = new Stack<String>();
                }
                old_object.push(object);
                String subject = triples[0].substring(1, triples[0].length() - 1);
                System.out.print("\nSubject=" + object);
                System.out.print("\ntriples[2]=" + triples[2]);
                hmLobid.put(subject, getAllCreators(new URI(subject)));
                hm.put(object, hmLobid);

            }
            // get all dbpedia resources
            for (String key_one : hm.keySet()) {
                System.out.print("\n==============\n==== " + key_one + "\n===============");
                int resources_cnt = hm.get(key_one).keySet().size();
                ArrayList<String>[] creators = new ArrayList[resources_cnt];
                HashMap<String, Integer> creators_backed = new HashMap<String, Integer>();
                int x = 0;
                // get all lobid_resources subsumed under the dbpedia resource
                for (String subject_uri : hm.get(key_one).keySet()) {
                    creators[x] = new ArrayList<String>();
                    System.out.print("\n     subject_uri=" + subject_uri);
                    Iterator<String> ite = hm.get(key_one).get(subject_uri).iterator();
                    int y = 0;
                    // get all creators of the lobid resource
                    while (ite.hasNext()) {
                        String creator = ite.next();
                        System.out.print("\n          " + creator);
                        if (creators_backed.containsKey(creator)) {
                            y = creators_backed.get(creator);
                        } else {
                            y = creators_backed.size();
                            creators_backed.put(creator, y);
                        }
                        while (creators[x].size() <= y) {
                            creators[x].add("-");
                        }
                        creators[x].set(y, creator);
                        y++;
                    }
                    x++;
                }
                if (creators_backed.size() == 1) {
                    System.out
                            .println("\n" + "Every resource pointing to " + key_one + " has the same creator!");
                    for (String key_two : hm.get(key_one).keySet()) {
                        output.append("<" + key_two + "> rdrel:workManifested <" + key_one + "> .\n");
                        output.append("<" + key_two + ">  mo:wikipedia <"
                                + key_one.replaceAll("dbpedia\\.org/resource", "wikipedia\\.org/wiki")
                                + "> .\n");
                    }
                } /*else  {
                    for (int a = 0; a < creators.length; a++) {
                       System.out.print(creators[a].toString()+",");
                    }
                  }*/
            }

            output.flush();
            if (output != null) {
                output.close();
            }
        } catch (Exception e) {
            System.out.print("Exception while working on " + filename + ": \n");
            e.printStackTrace(System.out);
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    File directory = new File("c:\\");

    if (!directory.isDirectory()) {
        System.out.println("No directory provided");
        return;/*from   w ww  .  ja v  a2s.c o  m*/
    }

    FilenameFilter filefilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }
    };

    String[] filenames = directory.list(filefilter);

    for (String name : filenames) {
        System.out.println(name);
    }
}