Java BufferedReader Read All readAllText(String path)

Here you can find the source of readAllText(String path)

Description

read All Text

License

Open Source License

Declaration

@SuppressWarnings("null")
    public static String readAllText(String path) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    @SuppressWarnings("null")
    public static String readAllText(String path) throws IOException {
        File file = new File(path);
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        try {//from ww  w .  j a v a  2 s  .c  o  m
            String line;
            br = new BufferedReader(new FileReader(file));
            while ((line = br.readLine()) != null) {
                sb.append(line + '\n');
            }
        } catch (IOException e) {
            try {
                br.close();
            } catch (NullPointerException e2) {
            }
            throw e;
        }

        br.close();
        return sb.toString();
    }
}

Related

  1. readAllText(File file)
  2. readAllText(File file)
  3. readAllText(final InputStream inputStream)
  4. readAllText(InputStream stream)
  5. readAllText(String filePath)
  6. readAllTextFromSystemResource(String path)