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(String path)
Reads and returns the text contained in a given file.
StringBuilder res = new StringBuilder();
try {
    BufferedReader in = new BufferedReader(new FileReader(path));
    String line = null;
    while ((line = in.readLine()) != null) {
        res.append(new String(line.getBytes(), "UTF-8") + "\n");
    in.close();
...
StringreadFile(String path)
read File
StringBuilder sb = new StringBuilder();
String sCurrentLine = "";
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
    while ((sCurrentLine = br.readLine()) != null) {
        sb.append(sCurrentLine);
return sb.toString();
...
StringreadFile(String path)
Read a text file from the given path and return the contents as a String.
return readFile(new File(path));
StringreadFile(String path)
Reads a file line after line.
FileReader reader = null;
BufferedReader buffReader = null;
StringBuilder text = new StringBuilder();
try {
    reader = new FileReader(path);
    buffReader = new BufferedReader(reader);
    String tempLine;
    while ((tempLine = buffReader.readLine()) != null) {
...
StringreadFile(String path)
Read file.
StringBuilder content = new StringBuilder();
BufferedReader br = null;
try {
    String sCurrentLine;
    br = new BufferedReader(new FileReader(path));
    while ((sCurrentLine = br.readLine()) != null) {
        content.append(sCurrentLine);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (br != null)
            br.close();
    } catch (IOException ex) {
        ex.printStackTrace();
return content.toString();
VectorreadFile(String path)
Reads a file into a Vector of Strings
BufferedReader reader = null;
Vector<String> contents = new Vector<String>();
try {
    reader = new BufferedReader(new FileReader(path));
    String line;
    while ((line = reader.readLine()) != null)
        contents.add(line);
} catch (Exception ex) {
...
ListreadFile(String path)
read File
List<String> lines = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader(path));
String line = reader.readLine();
while (line != null) {
    lines.add(line);
    line = reader.readLine();
reader.close();
...
StringreadFile(String path)
read File
return readFile(new File(path));
StringreadFile(String path)
read File
BufferedReader br = null;
try {
    br = new BufferedReader(new FileReader(path));
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    while (line != null) {
        sb.append(line + "\n");
        line = br.readLine();
...
StringreadFile(String path)
Reads file and stores into a string and returns it in one method
String str = "";
try {
    BufferedReader reader = new BufferedReader(new FileReader("path"));
    String tmp = "";
    while ((tmp = reader.readLine()) != null)
        str += "";
    reader.close();
} catch (IOException e) {
...