Java IO & NIO Java Java API
java.nio.file.Files
public static BufferedReader newBufferedReader(Path path, Charset cs) throws IOException
Opens a file for reading, returning a BufferedReader that may be used to read text from the file in an efficient manner.
BufferedReader
path
cs
public static BufferedReader newBufferedReader(Path path) throws IOException
Opens a file for reading, returning a BufferedReader to read text from the file in an efficient manner.
package com.logicbig.example.files;import java.io.BufferedReader;import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;public class NewBufferedReaderExample { public static void main(String... args) throws IOException { Path path = Files.write(Files.createTempFile("test", ".txt"), "test content".getBytes()); System.out.println("Using newBufferedReader for path: " + path); System.out.println("Reading lines: "); try (BufferedReader bufferedReader = Files.newBufferedReader(path)) { bufferedReader.lines().forEach(System.out::println); } }}
Using newBufferedReader for path: C:\Users\Joe\AppData\Local\Temp\test9978513373578826701.txtReading lines: test content