Java Utililty Methods BufferedReader Read All

List of utility methods to do BufferedReader Read All

Description

The list of methods to do BufferedReader Read All are organized into topic(s).

Method

ListreadAllLines(InputStream inputStream)
read All Lines
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
List<String> data = new ArrayList<>();
for (String line; (line = br.readLine()) != null;) {
    data.add(line);
return data;
ListreadAllLines(InputStream is)
read All Lines
List<String> ls = new ArrayList<String>();
BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = buffer.readLine()) != null) {
    ls.add(line);
return ls;
ListreadAllLines(String filepath)
read All Lines
List<String> fileContent = new ArrayList<String>();
File file = new File(filepath);
BufferedReader input = new BufferedReader(new FileReader(file));
try {
    String line = null;
    while ((line = input.readLine()) != null) {
        fileContent.add(line);
} finally {
    if (input != null)
        input.close();
return fileContent;
StringreadAllStreamFromClasspathBaseResource(Class resourceBase, String dataLocation)
read All Stream From Classpath Base Resource
if (isFileAvailableOnClasspath(resourceBase, dataLocation)) {
    return readFullStream(resourceBase.getResourceAsStream(dataLocation));
} else {
    return null;
ListreadAllStreamsFromClasspathBaseResource(Class resourceBase, String[] dataLocations)
read All Streams From Classpath Base Resource
final List<String> scriptContent = new ArrayList<String>();
for (int i = 0; i < dataLocations.length; i++) {
    String content = readAllStreamFromClasspathBaseResource(resourceBase, dataLocations[i]);
    if (content != null) {
        scriptContent.add(content);
return scriptContent;
...
StringreadAllText(File file)
read All Text
StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null)
    sb.append(line + "\n");
br.close();
return sb.toString();
StringreadAllText(File file)
Read the given file and return its contents as string
if (file == null || !file.exists())
    return null;
BufferedReader reader;
StringBuilder builder = new StringBuilder();
try {
    reader = new BufferedReader(new FileReader(file));
    String line;
    while ((line = reader.readLine()) != null)
...
StringreadAllText(final InputStream inputStream)
read All Text
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
    final StringBuffer buff = new StringBuffer();
    String line = null;
    while ((line = reader.readLine()) != null) {
        buff.append(line + System.lineSeparator());
    return buff.toString();
} catch (NullPointerException e) {
...
StringreadAllText(InputStream stream)
Reads all text from the stream using the default charset.
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder result = new StringBuilder();
while (true) {
    String s = reader.readLine();
    if (s == null) {
        return result.toString();
    result.append(s);
...
StringreadAllText(String filePath)
read All Text
BufferedReader reader = new BufferedReader(new FileReader(filePath));
StringBuilder result = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
    result.append(line).append("\r\n");
reader.close();
return result.toString();