首页 > 代码库 > 把流转换成字符串

把流转换成字符串

 

把流转换成字符串

public static String convertStreamToString(InputStream is) {        BufferedReader reader = null;        try {            reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));        } catch (UnsupportedEncodingException e1) {            e1.printStackTrace();        }        StringBuilder sb = new StringBuilder();        String line = null;        try {            while ((line = reader.readLine()) != null) {                sb.append(line + "\n");            }        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                is.close();            } catch (IOException e) {                e.printStackTrace();            }        }        return sb.toString();    }

 

把流转换成字符串