Here you can find the source of getContentFromInputStream(InputStream in, String charset)
get string content form inputStream with given charset
Parameter | Description |
---|---|
in | a parameter |
charset | a parameter |
public static String getContentFromInputStream(InputStream in, String charset)
//package com.java2s; import java.io.InputStream; import java.nio.charset.Charset; public class Main { /**//from w w w.j ava2 s .c om * <p> * get string content form inputStream with default charset ant return. * </p> * * @param in * @return */ public static String getContentFromInputStream(InputStream in) { return getContentFromInputStream(in, Charset.defaultCharset().name()); } /** * <p> * get string content form inputStream with given charset * </p> * * @param in * @param charset * @return */ public static String getContentFromInputStream(InputStream in, String charset) { StringBuffer dist = new StringBuffer(); byte[] data = new byte[1024]; int readNum = -1; try { while ((readNum = in.read(data)) != -1) { dist.append(new String(data, 0, readNum, charset)); } in.close(); } catch (Exception e) { e.printStackTrace(); } return dist.toString(); } }