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 f)
read File
String res = "";
BufferedReader br = null;
br = new BufferedReader(new FileReader(f));
String line = null;
while ((line = br.readLine()) != null) {
    res += line;
try {
...
StringreadFile(File f)
read File
BufferedReader br = null;
try {
    br = new BufferedReader(new FileReader(f));
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    while (line != null) {
        sb.append(line);
        line = br.readLine();
...
MapreadFile(File f)
read File
Map<String, String> map = new HashMap<>();
try {
    BufferedReader buffer = new BufferedReader(new FileReader(f));
    buffer.lines().filter(s -> s.matches("(?!#).*[ ]?=[ ]?.*")).forEach(s -> {
        String k[] = s.split("=");
        k[1] = k[1].split("#")[0].trim();
        map.put(k[0].trim(), k[1]);
    });
...
StringreadFile(File f)
read File
BufferedReader br = new BufferedReader(new FileReader(f));
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
int b = -1;
while ((b = br.read()) != -1) {
    baos.write(b);
baos.close();
return new String(baos.toByteArray());
...
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];
...
ListreadFile(File f)
Reads the content of a file and returns an ArrayList with the data
List<String> data = new ArrayList<String>();
try {
    BufferedReader br = new BufferedReader(new FileReader(f));
    while (br.ready()) {
        data.add(br.readLine());
    return data;
} catch (FileNotFoundException e) {
...
StringReadFile(File f, boolean keep_newline)
Read File
try {
    StringBuilder sb = new StringBuilder();
    java.io.BufferedReader br = new BufferedReader(new FileReader(f));
    String line = null;
    while ((line = br.readLine()) != null) {
        sb.append((sb.length() > 0 ? (keep_newline ? "\n" : " ") : "") + line);
    br.close();
...
StringreadFile(File f, boolean preserveLineBreaks)
read File
StringBuilder content = new StringBuilder();
String line = null;
BufferedReader br = null;
try {
    mylogger.log(Level.INFO, "Reading: [{0}] File: [{1}]",
            new Object[] { f.getName(), f.getAbsolutePath() });
    br = new BufferedReader(new FileReader(f));
    while ((line = br.readLine()) != null) {
...
StringreadFile(File f, String newLineChar)
Reads contents of file (f) into a String (up to five megs) using newLineChar as a line seperator
if (f.length() > 5000000)
    return "File too long";
BufferedReader buf = new BufferedReader(new FileReader(f));
StringBuffer results = new StringBuffer();
while (buf.ready()) {
    results.append(buf.readLine()).append(newLineChar);
return results.toString();
...
StringreadFile(File file)
Read string from a file
BufferedReader reader;
try {
    reader = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
    return "";
StringBuilder sb = new StringBuilder();
String line = reader.readLine();
...