首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java将inputstream写下文件&&InputStream转为string

2012-10-29 
java将inputstream写入文件&&InputStream转为stringpublic String inputStream2String(InputStream is)thr

java将inputstream写入文件&&InputStream转为string

public 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();    }

热点排行