Example usage for java.nio.file Path toFile

List of usage examples for java.nio.file Path toFile

Introduction

In this page you can find the example usage for java.nio.file Path toFile.

Prototype

default File toFile() 

Source Link

Document

Returns a File object representing this path.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("users.txt");

    if (path.toFile().exists()) {
        System.out.println("Real path: " + path.toRealPath(LinkOption.NOFOLLOW_LINKS));
    } else {//from ww w .  j a v  a 2 s.c  o  m
        System.out.println("The file does not exist");
    }
}

From source file:Main.java

public static void main(String[] args) {
    final String dir = "C:\\data\\projects\\";
    final Path path = Paths.get(dir);
    final File file = path.toFile();
    Stream.of(file.listFiles(File::isDirectory)).forEach(System.out::println);
    ;/*from   www  .j a  v  a 2 s  .c  o  m*/
}

From source file:com.github.ivkustoff.app.Application.java

public static void main(String[] args) {
    if (args != null && args.length > 0) {
        Path testRoot = Paths.get(args[0]);
        if (testRoot.toFile().exists()) {
            System.out.println("Parsing data...");
            DirCrawler crawler = new DirCrawler(testRoot).crawl();
            System.out.println(crawler.errors());
            List<ParsedTopicData> parsedTopicData = crawler.topics();
            List<Topic> realTopics = new ArrayList<>();
            for (ParsedTopicData topicData : parsedTopicData) {
                realTopics.add(new RealTopic(topicData).generateTopic());
            }//w  ww .jav a 2  s  .  c  o m
            System.out.println("Starting server...");
            ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
            applicationContext.getBean(TopicRepository.class).addTopics(realTopics);
        }
    } else {
        System.out.println("Please provide topicRoot directory as program argument");
    }
}

From source file:Main.java

public static void main(String[] args) {

    Path copy_from_4 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt");
    Path copy_to_4 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt");
    try (OutputStream os = new FileOutputStream(copy_to_4.toFile())) {

        Files.copy(copy_from_4, os);

    } catch (IOException e) {
        System.err.println(e);/*from  ww  w.  ja  v  a  2  s . c  om*/
    }

}

From source file:Main.java

public static void main(String[] args) {

    Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt");

    //convert path to File object
    File path_to_file = path.toFile();
    System.out.println("Path to file name: " + path_to_file.getName());
}

From source file:Main.java

public static void main(String[] args) {
    Path copy_from_2 = Paths.get("C:/tutorial/Java/JavaFX", "tutor.txt");
    Path copy_to_2 = Paths.get("C:/tutorial/Java/Swing", "tutor.txt");

    try (InputStream is = new FileInputStream(copy_from_2.toFile())) {

        Files.copy(is, copy_to_2, REPLACE_EXISTING);

    } catch (IOException e) {
        System.err.println(e);/*from   www . j a va2  s  .co  m*/
    }

}

From source file:de.tudarmstadt.ukp.dkpro.discourse.pdtbparser.PDTBParserWrapper.java

public static void main(String[] args) throws Exception {
    final PDTBParserWrapper pdtbParserWrapper = new PDTBParserWrapper();
    Path out = Files.createTempFile(pdtbParserWrapper.tempDirectory, "out", ".xml");
    pdtbParserWrapper.run(new File("src/main/resources/test302.txt"), out.toFile());
    pdtbParserWrapper.clean();//ww  w  .  ja  v  a2  s .c  o m
}

From source file:fr.cnrs.sharp.Main.java

public static void main(String args[]) {
    Options options = new Options();

    Option versionOpt = new Option("v", "version", false, "print the version information and exit");
    Option helpOpt = new Option("h", "help", false, "print the help");

    Option inProvFileOpt = OptionBuilder.withArgName("input_PROV_file_1> ... <input_PROV_file_n")
            .withLongOpt("input_PROV_files").withDescription("The list of PROV input files, in RDF Turtle.")
            .hasArgs().create("i");

    Option inRawFileOpt = OptionBuilder.withArgName("input_raw_file_1> ... <input_raw_file_n")
            .withLongOpt("input_raw_files")
            .withDescription(//from  w ww.j a v  a 2s. c o m
                    "The list of raw files to be fingerprinted and possibly interlinked with owl:sameAs.")
            .hasArgs().create("ri");

    Option summaryOpt = OptionBuilder.withArgName("summary").withLongOpt("summary")
            .withDescription("Materialization of wasInfluencedBy relations.").create("s");

    options.addOption(inProvFileOpt);
    options.addOption(inRawFileOpt);
    options.addOption(versionOpt);
    options.addOption(helpOpt);
    options.addOption(summaryOpt);

    String header = "SharpTB is a tool to maturate provenance based on PROV inferences";
    String footer = "\nPlease report any issue to alban.gaignard@univ-nantes.fr";

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("SharpTB", header, options, footer, true);
            System.exit(0);
        }

        if (cmd.hasOption("v")) {
            logger.info("SharpTB version 0.1.0");
            System.exit(0);
        }

        if (cmd.hasOption("ri")) {
            String[] inFiles = cmd.getOptionValues("ri");
            Model model = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    //1. fingerprint
                    try {
                        model.add(Interlinking.fingerprint(p));
                    } catch (IOException e) {
                        logger.error("Cannot fingerprint file " + inFile);
                    }
                }
            }
            //2. genSameAs
            Model sameAs = Interlinking.generateSameAs(model);
            sameAs.write(System.out, "TTL");
        }

        if (cmd.hasOption("i")) {
            String[] inFiles = cmd.getOptionValues("i");
            Model data = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    RDFDataMgr.read(data, inFile, Lang.TTL);
                }
            }
            Model res = Harmonization.harmonizeProv(data);

            try {
                Path pathInfProv = Files.createTempFile("PROV-inf-tgd-egd-", ".ttl");
                res.write(new FileWriter(pathInfProv.toFile()), "TTL");
                System.out.println("Harmonized PROV written to file " + pathInfProv.toString());

                //if the summary option is activated, then save the subgraph and generate a visualization
                if (cmd.hasOption("s")) {

                    String queryInfluence = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
                            + "PREFIX prov: <http://www.w3.org/ns/prov#> \n" + "CONSTRUCT { \n"
                            + "    ?x ?p ?y .\n" + "    ?x rdfs:label ?lx .\n" + "    ?y rdfs:label ?ly .\n"
                            + "} WHERE {\n" + "    ?x ?p ?y .\n"
                            + "    FILTER (?p IN (prov:wasInfluencedBy)) .\n" + "    ?x rdfs:label ?lx .\n"
                            + "    ?y rdfs:label ?ly .\n" + "}";

                    Query query = QueryFactory.create(queryInfluence);
                    QueryExecution queryExec = QueryExecutionFactory.create(query, res);
                    Model summary = queryExec.execConstruct();
                    queryExec.close();
                    Util.writeHtmlViz(summary);
                }

            } catch (IOException ex) {
                logger.error("Impossible to write the harmonized provenance file.");
                System.exit(1);
            }
        } else {
            //                logger.info("Please fill the -i input parameter.");
            //                HelpFormatter formatter = new HelpFormatter();
            //                formatter.printHelp("SharpTB", header, options, footer, true);
            //                System.exit(0);
        }

    } catch (ParseException ex) {
        logger.error("Error while parsing command line arguments. Please check the following help:");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("SharpToolBox", header, options, footer, true);
        System.exit(1);
    }
}

From source file:io.fabric8.vertx.maven.plugin.FileFilterMain.java

public static void main(String[] args) {

    Commandline commandline = new Commandline();
    commandline.setExecutable("java");
    commandline.createArg().setValue("io.vertx.core.Launcher");
    commandline.createArg().setValue("--redeploy=target/**/*");

    System.out.println(commandline);/*from  w w  w  . java 2s  .co m*/

    File baseDir = new File("/Users/kameshs/git/fabric8io/vertx-maven-plugin/samples/vertx-demo");
    List<String> includes = new ArrayList<>();
    includes.add("src/**/*.java");
    //FileAlterationMonitor monitor  = null;
    try {

        Set<Path> inclDirs = new HashSet<>();

        includes.forEach(s -> {
            try {

                if (s.startsWith("**")) {
                    Path rootPath = Paths.get(baseDir.toString());
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                } else if (s.contains("**")) {
                    String root = s.substring(0, s.indexOf("/**"));
                    Path rootPath = Paths.get(baseDir.toString(), root);
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                }

                List<Path> dirs = FileUtils.getFileAndDirectoryNames(baseDir, s, null, true, true, true, true)
                        .stream().map(FileUtils::dirname).map(Paths::get)
                        .filter(p -> Files.exists(p) && Files.isDirectory(p)).collect(Collectors.toList());

                inclDirs.addAll(dirs);

            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        FileAlterationMonitor monitor = fileWatcher(inclDirs);

        Runnable monitorTask = () -> {
            try {
                monitor.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        };

        monitorTask.run();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:io.reactiverse.vertx.maven.plugin.FileFilterMain.java

public static void main(String[] args) {

    Commandline commandline = new Commandline();
    commandline.setExecutable("java");
    commandline.createArg().setValue("io.vertx.core.Launcher");
    commandline.createArg().setValue("--redeploy=target/**/*");

    System.out.println(commandline);/* w  w  w . jav a 2s .  c o m*/

    File baseDir = new File("/Users/kameshs/git/reactiverse/vertx-maven-plugin/samples/vertx-demo");
    List<String> includes = new ArrayList<>();
    includes.add("src/**/*.java");
    //FileAlterationMonitor monitor  = null;
    try {

        Set<Path> inclDirs = new HashSet<>();

        includes.forEach(s -> {
            try {

                if (s.startsWith("**")) {
                    Path rootPath = Paths.get(baseDir.toString());
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                } else if (s.contains("**")) {
                    String root = s.substring(0, s.indexOf("/**"));
                    Path rootPath = Paths.get(baseDir.toString(), root);
                    if (Files.exists(rootPath)) {
                        File[] dirs = rootPath.toFile().listFiles((dir, name) -> dir.isDirectory());
                        Objects.requireNonNull(dirs);
                        Stream.of(dirs).forEach(f -> inclDirs.add(Paths.get(f.toString())));
                    }
                }

                List<Path> dirs = FileUtils.getFileAndDirectoryNames(baseDir, s, null, true, true, true, true)
                        .stream().map(FileUtils::dirname).map(Paths::get)
                        .filter(p -> Files.exists(p) && Files.isDirectory(p)).collect(Collectors.toList());

                inclDirs.addAll(dirs);

            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        FileAlterationMonitor monitor = fileWatcher(inclDirs);

        Runnable monitorTask = () -> {
            try {
                monitor.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        };

        monitorTask.run();

    } catch (Exception e) {
        e.printStackTrace();
    }

}