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)
This method read a whole file and return the content.
if (!file.exists()) {
    throw new IllegalArgumentException("Illegal path: unexisting");
if (!file.isFile()) {
    throw new IllegalArgumentException("Illegal path: not a dfile");
FileReader fr = null;
BufferedReader reader = null;
...
StringreadFile(File file)
read File
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
    String linesep = System.lineSeparator();
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    String line;
    while ((line = reader.readLine()) != null) {
        if (first) {
            sb.append(line);
...
String[]readFile(File file)
read File
ArrayList<String> done = new ArrayList<String>();
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    String current;
    while ((current = br.readLine()) != null) {
        done.add(current);
} catch (IOException e) {
    e.printStackTrace();
...
StringBufferreadFile(File file)
Read a file fully into a string buffer.
StringBuffer buf = new StringBuffer();
if (null == file) {
    return null;
if (!file.exists() || !file.canRead()) {
    throw new IOException("Error! File is not accessible : " + file);
BufferedReader reader = new BufferedReader(new FileReader(file));
...
StringreadFile(File file)
read File
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
    stringBuilder.append(line).append("\n");
fileReader.close();
...
StringreadFile(File file)
read File
StringBuffer stringBuffer = new StringBuffer();
try {
    BufferedReader in = new BufferedReader(new FileReader(file));
    try {
        char[] buffer = new char[1024];
        int size = 0;
        while ((size = in.read(buffer)) > -1) {
            stringBuffer.append(buffer, 0, size);
...
StringreadFile(File file)
read File
StringBuilder result = new StringBuilder();
BufferedReader fileReader = new BufferedReader(new FileReader(file));
String line = new String();
while ((line = fileReader.readLine()) != null) {
    result.append(line).append("\n");
fileReader.close();
return result.toString();
...
StringreadFile(File file)
Reads a file into a String
BufferedReader in = new BufferedReader(new FileReader(file));
String line = "";
while ((line += in.readLine()) != null)
    ;
return line;
StringreadFile(File file)
read File
BufferedReader fr = new BufferedReader(new FileReader(file));
try {
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = fr.readLine()) != null)
        sb.append(line).append("\n");
    return sb.toString();
} finally {
...
StringreadFile(File file)
read File
StringWriter out = new StringWriter();
FileInputStream in = null;
try {
    in = new FileInputStream(file);
    int i;
    while ((i = in.read()) != -1) {
        out.write(i);
} finally {
    in.close();
return out.toString();