Java Utililty Methods BufferedReader Read

List of utility methods to do BufferedReader Read

Description

The list of methods to do BufferedReader Read are organized into topic(s).

Method

StringBuilderreadFile(final File paramFile, final boolean paramWhitespaces)
Read a file into a StringBuilder.
final BufferedReader in = new BufferedReader(new FileReader(paramFile));
final StringBuilder sBuilder = new StringBuilder();
for (String line = in.readLine(); line != null; line = in.readLine()) {
    if (paramWhitespaces) {
        sBuilder.append(line + "\n");
    } else {
        sBuilder.append(line.trim());
if (paramWhitespaces) {
    sBuilder.replace(sBuilder.length() - 1, sBuilder.length(), "");
in.close();
return sBuilder;
StringreadFile(final String file)
read File
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(new File(file)));
    final StringBuilder sb = new StringBuilder();
    String line;
    while ((line = reader.readLine()) != null) {
        sb.append(line);
        sb.append(System.getProperty("line.separator"));
...
StringreadFile(final String fileName)
read File
return readAll(new FileReader(fileName));
ListreadFile(final String filename)
read File
final List<String> ret = new ArrayList<String>();
try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String inputLine;
    while ((inputLine = in.readLine()) != null)
        ret.add(inputLine);
    in.close();
} catch (Exception e) {
...
StringreadFile(final String fileName)
read File
final File file = new File(fileName);
char[] buffer = null;
try {
    final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
    buffer = new char[(int) file.length()];
    int i = 0;
    int c = bufferedReader.read();
    while (c != -1) {
...
StringreadFile(final String filePath)
Read text from a file in one line.
return readFile(new File(filePath));
StringreadFile(final String name)
Reads the contents of a file.
FileReader fileReader = null;
final StringBuilder contents = new StringBuilder();
try {
    final File file = new File(name);
    if (!file.exists()) {
        throw new IllegalArgumentException("File " + name + " does not exist");
    fileReader = new FileReader(file);
...
ListreadFile(final String path)
read File
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(path));
    final ArrayList<String> lines = new ArrayList<String>();
    String line;
    while ((line = reader.readLine()) != null) {
        lines.add(line);
    return lines;
} catch (Exception e) {
    throw new Exception("Can't read file: " + path, e);
} finally {
    closeNoThrow(reader);
StringBuilderreadFile(final String pFile)
read File
File bsCWT = new File(pFile);
@SuppressWarnings("resource")
BufferedReader reader = new BufferedReader(new FileReader(bsCWT));
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
    content.append(line + "\n");
return content;
List>readFile(List fieldNames, String filename)
read File
List<Map<String, String>> rows = new ArrayList<Map<String, String>>();
FileReader fr = new FileReader(filename);
BufferedReader br = new BufferedReader(fr);
br.lines().forEach(values -> {
    String[] vs = values.split(" ");
    Map<String, String> row = new HashMap<String, String>();
    for (int i = 0; i < fieldNames.size(); i++) {
        row.put(fieldNames.get(i), vs[i]);
...