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

StringreadFile(Reader reader)
read File
BufferedReader br = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
String read = br.readLine();
String newLine = System.getProperty("line.separator");
while (read != null) {
    sb.append(read);
    sb.append(newLine);
    read = br.readLine();
...
StringreadFile(String absoluteFilePath)
Read the contents of a file
try (BufferedReader bw = new BufferedReader(new FileReader(new File(absoluteFilePath)))) {
    String output = ""; 
    String tmp = ""; 
    while ((tmp = bw.readLine()) != null) {
        output += tmp + "\n"; 
    bw.close();
    return output;
...
String[]readFile(String aFileName)
read File
File aFile = new File(aFileName);
BufferedReader input = new BufferedReader(new FileReader(aFile));
ArrayList<String> outputBuffer = new ArrayList<String>();
try {
    String line = null; 
    while ((line = input.readLine()) != null) {
        outputBuffer.add(line);
} finally {
    input.close();
int nlines = outputBuffer.size();
String[] status = null;
if (nlines < 1) {
    status = new String[1];
    status[0] = "";
} else {
    status = new String[nlines];
    for (int il = 0; il < nlines; ++il) {
        status[il] = outputBuffer.get(il);
return status;
StringreadFile(String directory)
read File
String path = "", file;
String[] S = directory.split("/");
for (int i = 0; i < S.length - 1; i++)
    path += (S[i] + "/");
file = S[S.length - 1];
File dir = new File(path);
File arq = new File(dir, file);
String text = "";
...
ArrayListreadFile(String directory, String fileName)
Reads and returns the contents of a file as an ArrayList.
if (detectOS() == OTHER) {
    System.err.println("[FileUtil : readFile] Detected OS is not supported.");
    return null;
directory = checkDir(directory);
if (!new File(directory + fileName).exists()) {
    System.err.println("[FileUtil : readFile] File does not exist.");
    return null;
...
StringreadFile(String file)
read File
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
    e.printStackTrace();
    throw new RuntimeException("Can't find the file", e);
String line = null;
...
StringreadFile(String file)
read File
BufferedReader reader;
StringBuilder stringBuilder = new StringBuilder();
boolean toggle = false;
try {
    reader = new BufferedReader(new FileReader(file));
    String line = null;
    String ls = System.getProperty("line.separator");
    while ((line = reader.readLine()) != null) {
...
StringreadFile(String file)
read File
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
    stringBuilder.append(line);
    stringBuilder.append(ls);
return stringBuilder.toString();
ListreadFile(String file)
read File
List<String> lines = new ArrayList<String>();
File emailsFile = new File(file);
try {
    FileReader fread = new FileReader(emailsFile);
    BufferedReader buffReader = new BufferedReader(fread);
    String line = " ";
    while ((line = buffReader.readLine()) != null) {
        lines.add(line);
...
StringreadFile(String file)
Read the content of a file pointed by the input absolute file path.
BufferedReader reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
try {
    while ((line = reader.readLine()) != null) {
        stringBuilder.append(line);
    return stringBuilder.toString().trim();
...