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

StringreadInputStream(InputStream stream, Charset cs)
read Input Stream
try (final Reader reader = new BufferedReader(new InputStreamReader(stream, cs))) {
    final StringBuilder builder = new StringBuilder();
    final char[] buffer = new char[8192];
    int read;
    while ((read = reader.read(buffer, 0, buffer.length)) > 0) {
        builder.append(buffer, 0, read);
    return builder.toString();
...
StringreadInputStreamToString(InputStream instream, Charset charset)
Form a string from the contents of instream with charset charset .
return new String(readInputStreamToByteArray(instream), charset);
StringreadLineFromStream(InputStream is, StringBuffer buffer, CharsetDecoder decoder)
read Line From Stream
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int r = -1;
while ((r = is.read()) != '\n') {
    if (r == -1) {
        String out = decode(decoder, byteBuffer.toByteArray());
        buffer.append(out);
        return null;
    byteBuffer.write(r);
String out = decode(decoder, byteBuffer.toByteArray());
buffer.append(out);
return out;
ListreadLines(InputStream in, Charset cs)
Read all lines from a InputStream and return them in a java.util.List .
ArrayList<String> result = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, cs));
while (true) {
    String line = reader.readLine();
    if (line == null) {
        return result;
    result.add(line);
...
ListreadLines(InputStream input, Charset charset)
Returns the lines of an InputStream as a list of Strings.
final InputStreamReader reader = new InputStreamReader(input, charset);
return readLines(reader);
CollectionreadLines(InputStream is, CharsetDecoder decoder)
read Lines
InputStreamReader reader = new InputStreamReader(is, decoder);
BufferedReader br = new BufferedReader(reader);
List<String> lines = new ArrayList<String>();
String line = null;
while ((line = br.readLine()) != null) {
    lines.add(line);
return lines;
...
ListreadLines(String filePath, Charset charset)
read Lines
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charset));
List<String> result = new ArrayList<String>();
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
    line = line.replaceAll("#.*$", "");
    line = line.trim();
    if (line.isEmpty())
        continue;
    result.add(line);
...
ListreadLines(String path, Charset charset)
read lines from file
if (!(new File(path)).exists()) {
    throw new FileNotFoundException("Couldnt find file: " + path);
return Files.readAllLines(Paths.get(path), charset);
StringreadNextWord(BufferedInputStream in, Charset cs)
read Next Word
byte[] buf = new byte[MAX_TERM_LENGTH];
try {
    int p = 0;
    char ch = (char) in.read();
    while (Character.isWhitespace(ch)) {
        ch = (char) in.read();
    while (!Character.isWhitespace(ch)) {
...
StringreadStreamAsString(final InputStream iStream, Charset iCharset)
read Stream As String
final StringBuffer fileData = new StringBuffer(1000);
final BufferedReader reader = new BufferedReader(new InputStreamReader(iStream, iCharset));
try {
    final char[] buf = new char[1024];
    int numRead = 0;
    while ((numRead = reader.read(buf)) != -1) {
        String readData = String.valueOf(buf, 0, numRead);
        if (fileData.length() == 0 && readData.startsWith(UTF8_BOM))
...