输入流返回字符串

来源:互联网 发布:上海软件企业认定 编辑:程序博客网 时间:2024/06/05 11:20
public class StreamTools {    /**     * @param is 输入流     * @return String 返回的字符串     * @throws IOException      */    public static String readFromStream(InputStream is) throws IOException{        ByteArrayOutputStream baos = new ByteArrayOutputStream();        byte[] buffer = new byte[1024];        int len = 0;        while((len = is.read(buffer))!=-1){            baos.write(buffer, 0, len);        }        is.close();        String result = baos.toString();        baos.close();        return result;    }}
0 0
原创粉丝点击