Java Utililty Methods Path File Read nio

List of utility methods to do Path File Read nio

Description

The list of methods to do Path File Read nio are organized into topic(s).

Method

PropertiesloadFromFile(Path path)
load From File
Properties props = new Properties();
props.load(Files.newInputStream(path));
return props;
JsonNodeloadJSON(Path path)
load JSON
try (final Reader input = Files.newBufferedReader(path, StandardCharsets.UTF_8);) {
    return loadJSON(input);
PropertiesloadProperties(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;
PropertiesloadProperties(Supplier classLoader, String classpathResource)
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);
ListloadStrings(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();
...
ListloadStringsFromFile(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;
voidloadTitles(Path rootDir, Set container)
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);
BufferedReadernewBufferedReader(Path path)
new Buffered Reader
return newBufferedReader(path, StandardCharsets.UTF_8);
BufferedReadernewBufferedReader(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;