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

StringreadLine(BufferedReader br, Path path)
read Line
try {
    return br.readLine();
} catch (IOException e) {
    throw new IOException("Can't read from file: " + path, e);
StringreadLineByLine(String filePath)
read Line By Line
StringBuilder contentBuilder = new StringBuilder();
try (Stream<String> stream = Files.lines(Paths.get(filePath), StandardCharsets.UTF_8)) {
    stream.forEach(s -> contentBuilder.append(s).append("\n"));
} catch (IOException e) {
    e.printStackTrace();
return contentBuilder.toString();
ListreadLines(Path path, boolean ignoreComments)
read Lines
File file = path.toFile();
if (!file.exists() || !file.isFile()) {
    return new ArrayList<>();
List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
    String line;
    while ((line = reader.readLine()) != null) {
...
StringreadLineS(String filePath, int line)
Read the context of a specified line in a text file.
File f = new File(filePath);
List<String> lines = Files.readAllLines(f.toPath());
return lines.get(line - 1);
ListreadLinesFromFile(Path path)
read Lines From File
try {
    return Files.readAllLines(path, StandardCharsets.UTF_8);
} catch (IOException e) {
    throw new UnsupportedOperationException("Could not read from file '" + path + "'", e);
StreamreadLinesFromFileLazy(String path)
read Lines From File Lazy
return Files.lines(Paths.get(path), Charset.defaultCharset());
ListreadLinesOfFile(String path)
read Lines Of File
Path pathToFile = Paths.get(path);
return Files.readAllLines(pathToFile, StandardCharsets.US_ASCII);
StringreadLineSP(String filePath, int line, int pos)
Read the context after a specified position of a line in a text file.
pos -= 1;
String l = readLineS(filePath, line);
if (l.length() < pos)
    pos = l.length();
l = l.substring(pos, l.length());
return l;
StringreadLinesToString(Path file)
read Lines To String
final StringBuilder sb = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader(file.toFile()), BUF_SIZE)) {
    reader.lines().forEach(line -> {
        sb.append(line);
        sb.append('\n');
    });
return sb.toString();
...
MapreadManifest(Path path)
read Manifest
try (InputStream fileInput = Files.newInputStream(path);
        InputStream input = new BufferedInputStream(fileInput)) {
    Properties properties = new Properties();
    properties.load(input);
    Map<String, String> result = new HashMap<>(2 * properties.size());
    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        result.put(entry.getKey().toString(), entry.getValue().toString());
    return result;