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

StringloadXMLDocumentFromClasspath(String resourcePath)
Utility to load Sample XMLs off the test classpath.
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
try {
    String line;
    while ((line = br.readLine()) != null) {
        sb.append(line);
    br.close();
    is.close();
} catch (IOException io) {
    throw new RuntimeException("Some problem retrieving a file from the classpath...");
return sb.toString();
double[]loadY(InputStream filePath)
load Y
String line;
double[] data;
List<Double> list = new ArrayList<Double>();
BufferedReader reader = null;
try {
    reader = new BufferedReader(new InputStreamReader(filePath));
    while ((line = reader.readLine()) != null) {
        list.add(Double.parseDouble(line.trim()));
...
StringreadFile(File f)
Reads in a file.
BufferedReader r = new BufferedReader(new FileReader(f));
StringBuilder builder = new StringBuilder();
int c;
while ((c = r.read()) != -1) {
    builder.append((char) c);
return builder.toString();
StringreadFile(File f)
read File
try (BufferedReader br = new BufferedReader(new FileReader(f))) {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    while (line != null) {
        sb.append(line);
        sb.append(System.lineSeparator());
        line = br.readLine();
    return sb.toString();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
return null;
StringreadFile(File f)
read File
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(f));
boolean first = true;
for (String line = reader.readLine(); line != null; line = reader.readLine(), first = false) {
    if (!first)
        builder.append("\n");
    builder.append(line);
return builder.toString();
StringreadFile(File f)
read File
StringBuilder contents = new StringBuilder();
try {
    BufferedReader input = new BufferedReader(new FileReader(f));
    try {
        String line = null;
        while ((line = input.readLine()) != null) {
            contents.append(line);
            contents.append(System.getProperty("line.separator"));
...
String[]readFile(File f)
Reads every line from a given text file.
BufferedReader in = new BufferedReader(new FileReader(f));
ArrayList list = new ArrayList();
String line;
while ((line = in.readLine()) != null)
    list.add(line);
return (String[]) list.toArray(new String[0]);
StringreadFile(File f)
read File
StringBuilder b = new StringBuilder();
BufferedReader in = new BufferedReader(new FileReader(f));
for (int c; (c = in.read()) != -1; b.append((char) c))
    ;
in.close();
return b.toString();
StringreadFile(File f)
read File
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String str;
while ((str = br.readLine()) != null) {
    sb.append(str);
    sb.append("\n");
br.close();
...
StringreadFile(File f)
read File
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(f));
char[] buf = new char[1024];
int numRead = 0;
while ((numRead = reader.read(buf)) != -1) {
    String readData = String.valueOf(buf, 0, numRead);
    fileData.append(readData);
    buf = new char[1024];
...