Java Text File Read by Charset readAll(InputStream in, Charset charset)

Here you can find the source of readAll(InputStream in, Charset charset)

Description

read All

License

Open Source License

Declaration

public static String readAll(InputStream in, Charset charset) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;

public class Main {
    public static String readAll(InputStream in, Charset charset) throws IOException {
        StringWriter output = new StringWriter();
        byte[] buffer = new byte[4096];
        int n;/*from ww  w. j  a va2 s  .co m*/
        while (-1 != (n = in.read(buffer))) {
            output.write(new String(buffer, 0, n, charset));
        }
        return output.toString();
    }
}

Related

  1. read(File file, Charset charset)
  2. read(InputStream _is, CharsetDecoder _decoder)
  3. read(InputStream in, Charset charset)
  4. read(InputStream in, Charset cs, Appendable appendable, int capacity)
  5. read(InputStream in, String charsetName)
  6. readAll(InputStream inputStream, Charset charset)
  7. readAll(InputStream inputStream, Charset encoding)
  8. readAllLines(File file, Charset cs, String newLineDelimiter)
  9. readAllLines(InputStream stream, Charset charset)