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

ListreadFile(String path)
read File
List<String> contexts = new ArrayList<>();
try {
    Stream<String> content = Files.lines(Paths.get(path));
    Stream<String> tuples = content.flatMap(line -> {
        return Arrays.stream(line.split(";")).map(t -> {
            String[] values = t.split(",");
            String label = values[0];
            String[] predicates = values[1].split("_");
...
StringreadFile(String path)
read File
StringBuilder everything = new StringBuilder();
try (InputStreamReader isr = new InputStreamReader(
        Thread.currentThread().getContextClassLoader().getResourceAsStream(path), Charset.forName("UTF-8"));
        BufferedReader bufferedReader = new BufferedReader(isr);) {
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        everything.append(line);
return everything.toString().replaceAll("\\s", "").replaceAll("\\r|\\n", "");
voidreadFile(String path)
read File
Reader reader = new InputStreamReader(new FileInputStream(path), UTF8);
try {
    int c = reader.read();
    System.out.println(c);
} finally {
    reader.close();
ListreadFile(String path)
read File
List<String> contexts = new ArrayList<>();
try {
    Stream<String> content = Files.lines(Paths.get(path));
    Stream<String> tuples = content.flatMap(line -> {
        return Arrays.stream(line.split(";")).map(t -> {
            String[] values = t.split(",");
            String label = values[0];
            String[] predicates = values[1].split("_");
...
StringreadFileAsString(String filePath)
read File As String
StringBuilder fileData = new StringBuilder(1000);
BufferedReader reader = new BufferedReader(new FileReader(filePath));
char[] buf = new char[1024];
int numRead;
while ((numRead = reader.read(buf)) != -1) {
    String readData = String.valueOf(buf, 0, numRead);
    fileData.append(readData);
    buf = new char[1024];
...
StringreadFileAsString(String path)
read File As String
InputStream is = ClassLoader.getSystemResourceAsStream(path);
InputStreamReader inputStreamREader = null;
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
try {
    inputStreamREader = new InputStreamReader(is, StandardCharsets.UTF_8);
    br = new BufferedReader(inputStreamREader);
    String content = br.readLine();
...
ListreadFileByLines(String filePath)
read File By Lines
Path path = new File(filePath).toPath();
return readFileByLines(path);
StringreadFileIntoString(Path path)
read File Into String
try {
    return Files.lines(path).collect(Collectors.joining("\n"));
} catch (IOException e) {
    throw new RuntimeException(e);
ListreadFileLines(Path file)
Internal method read a file.
return Files.readAllLines(file);
ListreadFileRows(Path path)
read File Rows
List<String> list = new LinkedList<>();
BufferedReader br = createBufferedReader(path);
try {
    String line;
    while ((line = br.readLine()) != null) {
        list.add(line);
    return list;
...