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)
Auslesen einer Datei in einen String
if (!file.exists()) {
    String errorMsg = "File '" + file + "' existiert nicht";
if (!file.exists()) {
    String errorMsg = "File '" + file + "' kann nicht gelesen werden nicht";
StringBuffer result = new StringBuffer();
try {
...
StringreadFile(File file)
read File
String fileContents = "";
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    String line;
    while ((line = br.readLine()) != null)
        fileContents += (line + System.lineSeparator());
return fileContents;
StringreadFile(File file)
Read file content using platform encoding and converting line endings to \\n.
StringBuilder buffer = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file)); 
String line;
while ((line = reader.readLine()) != null) {
    if (buffer.length() > 0) {
        buffer.append('\n');
    buffer.append(line);
...
StringreadFile(File file)
create a String from given File
StringBuffer buf = new StringBuffer();
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(file));
    String tempString = null;
    int line = 1;
    while ((tempString = reader.readLine()) != null) {
        buf.append(tempString);
...
StringreadFile(File file)
read File
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder builder = new StringBuilder();
String line;
boolean addPreviousLinebreak = false;
while ((line = reader.readLine()) != null) {
    if (addPreviousLinebreak)
        builder.append("\n");
    builder.append(line);
...
StringreadFile(File file)
Reads a file.
StringBuilder src = new StringBuilder();
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(file));
    String line = null;
    while ((line = reader.readLine()) != null)
        src.append(line).append("\n");
} catch (IOException ex) {
...
StringreadFile(File file)
Simply read a file's contents into a string object.
StringBuilder text = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
try {
    String line = null;
    while ((line = reader.readLine()) != null) {
        text.append(line + System.getProperty("line.separator"));
} finally {
...
StringreadFile(File file)
read File
StringBuilder out = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(file));
for (String line = br.readLine(); line != null; line = br.readLine())
    out.append(line + "\n");
br.close();
return out.toString();
StringreadFile(File file)
read File
StringBuffer fileBuffer;
String fileString = null;
String line;
try {
    FileReader in = new FileReader(file);
    BufferedReader dis = new BufferedReader(in);
    fileBuffer = new StringBuffer();
    while ((line = dis.readLine()) != null) {
...
StringreadFile(File file)
read file with lines separated by LF
StringBuilder sb = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    String l;
    while ((l = br.readLine()) != null) {
        sb.append(l).append("\n");
return sb.toString();
...