现在的位置: 首页 > 综合 > 正文

java下的相关知识

2014年10月24日 ⁄ 综合 ⁄ 共 425字 ⁄ 字号 评论关闭

1 、inputStream转换成String类型

public static String inputStream2String(InputStream is)
            throws UnsupportedEncodingException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,
                "utf-8"));
        StringBuffer sb = new StringBuffer();
        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();
    }

抱歉!评论已关闭.