Java Utililty Methods Text File Read by Charset

List of utility methods to do Text File Read by Charset

Description

The list of methods to do Text File Read by Charset are organized into topic(s).

Method

StringreadAll(InputStream inputStream, Charset charset)
Read all stream byte data into String
return readAll(inputStream, charset.name());
StringreadAll(InputStream inputStream, Charset encoding)
read All
try (Reader reader = new InputStreamReader(inputStream, encoding)) {
    return readAll(reader);
StringreadAllLines(File file, Charset cs, String newLineDelimiter)
read All Lines
final StringBuilder sb = new StringBuilder();
try (InputStream in = new FileInputStream(file);
        final InputStreamReader reader = new InputStreamReader(in, cs);
        final BufferedReader buffer = new BufferedReader(reader)) {
    String line;
    while ((line = buffer.readLine()) != null) {
        sb.append(line);
        if (newLineDelimiter != null) {
...
ListreadAllLines(InputStream stream, Charset charset)
Reads all lines using a BufferedReader and the given charset.
if (stream == null) {
    return Collections.emptyList();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) {
    return reader.lines().collect(Collectors.toList());
} catch (IOException e) {
    throw new IOException("An error occurred during reading lines.", e);
ListreadAllLines(Path path, Charset cs)
read All Lines
try {
    return Files.readAllLines(path, cs);
} catch (IOException e) {
    throw new RuntimeException(e);
StringreadAllText(File file, Charset charset)
read All Text
try {
    return readAllText(new FileInputStream(file), charset);
} catch (FileNotFoundException e) {
    return null;
StringreadAllText(File file, Charset charset)
read All Text
try {
    StringBuilder sb = new StringBuilder();
    LineNumberReader reader = new LineNumberReader(new FileReader(file));
    String line = null;
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    return sb.toString();
...
StringreadAsString(InputStream in, Charset charset)
read As String
return new String(readAsBytes(in), charset);
StringreadAsString(InputStream is, CharsetDecoder decoder)
read As String
InputStreamReader reader = new InputStreamReader(is, decoder);
return readAsString(reader);
char[]readCharsWithEncoding(File file, Charset charset)
read Chars With Encoding
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), charset);
BufferedReader br = new BufferedReader(isr);
char[] chars = new char[(int) file.length()];
br.read(chars);
isr.close();
br.close();
return chars;