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(File file)
read File
StringBuilder sb = new StringBuilder();
FileReader fr = null;
BufferedReader br = null;
try {
    fr = new FileReader(file);
    br = new BufferedReader(fr);
    String line;
    while ((line = br.readLine()) != null) {
...
StringreadFile(File file)
read File
BufferedReader reader = new BufferedReader(new FileReader(file));
String strLine;
StringBuilder sbString = new StringBuilder();
while ((strLine = reader.readLine()) != null) {
    sbString.append(strLine);
return sbString.toString();
StringreadFile(File file)
read File
if (!file.exists())
    return null;
StringBuilder text = new StringBuilder("");
BufferedReader reader = new BufferedReader(new FileReader(file));
try {
    String line;
    while ((line = reader.readLine()) != null) {
        text.append(line);
...
StringreadFile(File file)
read File
String allText = null;
try {
    FileReader fileReader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuffer stringBuffer = new StringBuffer();
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        stringBuffer.append(line);
...
StringreadFile(File file)
readFile read a file given File object and return the contents as a String
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new FileReader(file));
String str;
while ((str = br.readLine()) != null)
    sb.append(str);
br.close();
return sb.toString();
StringreadFile(File file, boolean useSystemLineSeparator)
read File
StringBuffer stringBuffer = new StringBuffer();
try {
    BufferedReader in = new BufferedReader(new FileReader(file));
    try {
        int size = 0;
        char[] buff = new char[512];
        while ((size = in.read(buff)) >= 0) {
            stringBuffer.append(buff, 0, size);
...
double[][]readFile(File file, int header)
Generic function to read a text file into a double[][] with an arbitrary number of columns.
double[][] output = null;
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(file));
    for (int i = 1; i <= header; i++) {
        reader.readLine();
    String line = reader.readLine();
...
ArrayListreadFile(File filename)
reads file into ArrayList.
ArrayList<String> lines = new ArrayList<String>();
try {
    BufferedReader br = new BufferedReader(new FileReader(filename));
    try {
        String line = "";
        while ((line = br.readLine()) != null) {
            lines.add(line);
        br.close();
    } catch (IOException e) {
        System.err.println("Read error " + e);
} catch (Exception e) {
    e.printStackTrace();
return lines;
StringBufferreadFile(File from)
Read the contents of a file into a StringBuffer
BufferedReader in = new BufferedReader(new FileReader(from));
StringWriter sWriter = new StringWriter();
BufferedWriter out = new BufferedWriter(sWriter);
int c;
while ((c = in.read()) != -1)
    out.write(c);
in.close();
out.close();
...
StringreadFile(File in)
Reads a file and converts it to a String via a byte array and inputStream.available() I'm not positive that inputStream.available() works the same under multi-threading
String line = null;
StringBuffer content = new StringBuffer("");
try {
    BufferedReader bReader = new BufferedReader(new FileReader(in));
    while ((line = bReader.readLine()) != null)
        content.append(line + "\n");
    bReader.close();
} catch (IOException ioe) {
...