Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

In this page you can find the example usage for java.nio.file Paths get.

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:de.fraunhofer.iais.eis.jrdfb.util.FileUtils.java

public static String readFile(String path, Charset encoding) {
    byte[] encoded = new byte[0];
    try {/* w w w .ja  v a 2 s.  c o m*/
        encoded = Files.readAllBytes(Paths.get(path));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new String(encoded, encoding);
}

From source file:mn.EngineForge.module.general.java

static private String readFile(String path, Charset encoding) throws IOException {
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return new String(encoded, encoding);
}

From source file:dev.meng.wikipedia.profiler.Cleaner.java

public static void cleanDB(List<String> values) {
    for (String value : values) {
        try {/*from  w w w. j  av  a 2  s . c  o  m*/
            String[] splits = value.split(":");
            Path filepath = Paths.get(splits[splits.length - 1]);
            Files.deleteIfExists(filepath);
        } catch (IOException ex) {
            LogHandler.console(Cleaner.class, ex);
        }
    }
}

From source file:Main.java

public static void writeUrlToFileNIO(String urlToRead, String folderToWrite, String fileName)
        throws MalformedURLException, IOException {
    URL urlIn = new URL(urlToRead);
    File folderOut = Paths.get(folderToWrite).toFile();
    if (!(folderOut.exists() || folderOut.mkdirs())) {
        throw new RuntimeException("could not create folder " + folderToWrite);
    }// w ww .j  av  a2s  .  c  om
    Path pathOut = Paths.get(folderToWrite, fileName);
    try (ReadableByteChannel in = Channels.newChannel(new BufferedInputStream(urlIn.openStream()));
            WritableByteChannel out = Files.newByteChannel(pathOut, CREATE, WRITE);) {
        transfer(in, out);
    }
}

From source file:io.github.casnix.spawnerdropper.Config.java

public static int GetTNTChance() {
    try {// ww  w  .  jav  a  2s. c om
        // Read entire ./SpawnerDropper/SpawnerDropperConfig.json into a string
        //         System.out.println("[SD DEBUG] 1");
        String configTable = new String(
                Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerDropperConfig.json")));

        // get the value of JSON->{spawnerType}
        //      System.out.println("[SD DEBUG] 2");
        JSONParser parser = new JSONParser();

        //   System.out.println("[SD DEBUG] 3");
        Object obj = parser.parse(configTable);

        //System.out.println("[SD DEBUG] 4");
        JSONObject jsonObj = (JSONObject) obj;

        //         System.out.println("[SD DEBUG] 5");
        String chance = (String) jsonObj.get("tntpercent");

        //      System.out.println("[SD DEBUG] 6");
        //         if(chance != null)
        //      System.out.println("[SD DBG MSG] "+chance);
        //         else
        //   System.out.println("[SD DBG MSG] chance is null");

        //         System.out.println("[SD DEBUG] 7");
        return Integer.valueOf(chance);
        //System.out.println("[SD DEBUG] 6");
        //return chance;
    } catch (ParseException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetTNTChance(void)");
        e.printStackTrace();

        return -1;
    } catch (FileNotFoundException e) {
        Bukkit.getLogger()
                .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerDropperConfig.json");
        e.printStackTrace();

        return -1;
    } catch (IOException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetTNTChance(void)");
        e.printStackTrace();

        return -1;
    }
}

From source file:io.github.casnix.spawnerdropper.SpawnerStack.java

public static long GetSpawnersInService(String spawnerType) {
    try {/*from   w w w . j  a  v a2 s  .  co m*/
        // Read entire ./SpawnerDropper.SpawnerStack.json into a string
        String spawnerStack = new String(
                Files.readAllBytes(Paths.get("./plugins/SpawnerDropper/SpawnerStack.json")));

        // get the value of JSON->{spawnerType}
        JSONParser parser = new JSONParser();

        Object obj = parser.parse(spawnerStack);

        JSONObject jsonObj = (JSONObject) obj;

        long number = (Long) jsonObj.get(spawnerType);

        //         System.out.println("[SD DBG MSG] GSIS numberInServer("+number+")");

        return number;
    } catch (ParseException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught ParseException in GetSpawnersInService(String)");
        e.printStackTrace();

        return -1;
    } catch (FileNotFoundException e) {
        Bukkit.getLogger()
                .warning("[SpawnerDropper] Could not find ./plugins/SpawnerDropper/SpawnerStack.json");
        e.printStackTrace();

        return -1;
    } catch (IOException e) {
        Bukkit.getLogger().warning("[SpawnerDropper] Caught IOException in GetSpawnersInService(String)");
        e.printStackTrace();

        return -1;
    }

}

From source file:com.teradata.presto.yarn.test.utils.Resources.java

public static Path extractResource(String resourcePath) {
    URL fixScriptResource = Resources.class.getResource(resourcePath);
    File temporaryFile = new File(tempDir, Paths.get(resourcePath).getFileName().toString());
    try {//from   w ww  .  j a va2s  .com
        FileUtils.copyURLToFile(fixScriptResource, temporaryFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Paths.get(temporaryFile.toURI());
}

From source file:dev.meng.wikipedia.profiler.Cleaner.java

public static void cleanData(List<String> values) {
    for (String value : values) {
        try {/*from w  ww  . ja v a  2  s  .  com*/
            Path filepath = Paths.get(value);
            File file = filepath.toFile();
            if (file.exists()) {
                if (file.isFile()) {
                    Files.delete(filepath);
                } else if (file.isDirectory()) {
                    FileUtils.deleteDirectory(file);
                }
            }
        } catch (IOException ex) {
            LogHandler.console(Cleaner.class, ex);
        }
    }
}

From source file:bit.changepurse.wdk.bip.TestBip39JP.java

public static String readTestVectors() {
    URL resource = TestBip39JP.class.getResource(TEST_VECTORS);
    Path path = Paths.get(newURI(resource));
    return readTextFile(path);
}

From source file:ex4.java

private static String readFile(String path, Charset encoding) throws IOException {
    byte[] encoded = Files.readAllBytes(Paths.get(path));
    return new String(encoded, encoding);
}