Java Utililty Methods InputStreamReader Read

List of utility methods to do InputStreamReader Read

Description

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

Method

StringreadFile(File file, String encoding)
Helper method to read the file's content into a String
InputStreamReader in = new InputStreamReader(new FileInputStream(file), encoding);
BufferedReader reader = new BufferedReader(in);
StringBuilder fileContent = new StringBuilder();
String line = reader.readLine();
while (line != null) {
    fileContent.append(line).append('\n');
    line = reader.readLine();
return fileContent.toString();
StringreadFile(File file, String encoding)
read File
InputStream inputStream = new FileInputStream(file);
return toString(encoding, inputStream);
StringreadFile(File filename)
read File
StringBuilder result = new StringBuilder();
InputStream ips = new FileInputStream(filename);
InputStreamReader ipsr = new InputStreamReader(ips);
try (BufferedReader br = new BufferedReader(ipsr)) {
    String line;
    while ((line = br.readLine()) != null) {
        result.append(line).append("\n");
return result.toString();
StringreadFile(File path)
Reads the entire contents of the file at the given path and returns it as a String.
InputStreamReader reader = null;
try {
    StringWriter writer = new StringWriter();
    reader = new InputStreamReader(new FileInputStream(path));
    int n;
    char[] buffer = new char[BUFFER_SIZE];
    while ((n = reader.read(buffer)) != -1) {
        writer.write(buffer, 0, n);
...
StringreadFile(File resultFile)
read File
StringBuilder result = new StringBuilder();
InputStream fileIn = new FileInputStream(resultFile);
try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(fileIn));
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            result.append(line);
...
StringBufferreadFile(File target)
Return a buffer containing the contents of the file at the specified location.
return readFile(new FileInputStream(target));
StringreadFile(FileInputStream file)
Reads an entire file into a string.
BufferedReader reader = new BufferedReader(new InputStreamReader(file, "UTF-8"));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
    builder.append(line);
reader.close();
return builder.toString();
...
StringreadFile(final File file)
read File
final StringBuilder sb = new StringBuilder();
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
    String line = null;
    while ((line = reader.readLine()) != null) {
        sb.append(line);
        sb.append("\n");
return sb.toString();
StringreadFile(final File inputFile)
read File
InputStreamReader in = null;
try {
    in = new InputStreamReader(new FileInputStream(inputFile), "US-ASCII");
    StringBuilder builder = new StringBuilder();
    final char[] buf = new char[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        builder.append(buf, 0, len);
...
BufferedReaderreadFile(final String aFileName)
read File
final InputStream stream = new FileInputStream(aFileName);
return new BufferedReader(new InputStreamReader(stream));