List of utility methods to do Path File Read nio
Properties | loadFromFile(Path path) load From File Properties props = new Properties(); props.load(Files.newInputStream(path)); return props; |
JsonNode | loadJSON(Path path) load JSON try (final Reader input = Files.newBufferedReader(path, StandardCharsets.UTF_8);) { return loadJSON(input); |
Properties | loadProperties(Path filePath) load Properties if (!Files.exists(filePath)) return null; try (Reader r = Files.newBufferedReader(filePath)) { Properties props = new Properties(); props.load(r); return props; |
Properties | loadProperties(Supplier Atomically load the properties file at the given location within the designated class loader. try (InputStream stream = classLoader.get().getResourceAsStream(classpathResource)) { Properties props = new Properties(); props.load(stream); return props; } catch (IOException e) { throw new IllegalStateException("Unable to find or read the '" + classpathResource + "' file using the " + classLoader + " class loader", e); |
List | loadStrings(Path thePath) load Strings try { BufferedReader reader = Files.newBufferedReader(thePath); List<String> myResult = new ArrayList<>(); String line = null; while ((line = reader.readLine()) != null) { myResult.add(line); reader.close(); ... |
List | loadStringsFromFile(String pathToFile) Loads a text file and returns a list containing one string per line in the file. List<String> inputLines = Files.lines(Paths.get(pathToFile)).collect(Collectors.toList());
return inputLines;
|
byte[] | loadTestPackets(final Path path) load Test Packets final File file = path.toFile(); final int size = (int) file.length(); final byte[] data = new byte[size]; final FileInputStream in = new FileInputStream(file); in.read(data); in.close(); return data; |
void | loadTitles(Path rootDir, Set load Titles Path coreFolder = rootDir.resolve("core"); if (Files.isDirectory(coreFolder)) { Path titleFile = coreFolder.resolve("titles.txt"); if (Files.isRegularFile(titleFile)) { doLoadTitles(Files.newBufferedReader(rootDir, Charset.defaultCharset()), container); |
BufferedReader | newBufferedReader(Path path) new Buffered Reader return newBufferedReader(path, StandardCharsets.UTF_8);
|
BufferedReader | newBufferedReader(Path path) This method is able to determine whether a file is GZipped and return a BufferedReader in any case BufferedReader br = null; if (path.toFile().getName().endsWith(".gz")) { br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(path.toFile())))); } else { br = Files.newBufferedReader(path, Charset.defaultCharset()); return br; |