把流转换成字符串

把流转换成字符串

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();
    }
时间: 2024-08-02 15:14:17

把流转换成字符串的相关文章

delphi 怎么将一个文件流转换成字符串(String到流,String到文件,相互转化)

//from   http://kingron.myetang.com/zsfunc0d.htm (*//   标题:充分利用pascal字符串类型   说明:和PChar不同,string可以保存#0字符在其中;示例文件.内存流字符串之间转换   设计:Zswang   日期:2002-01-25   支持:[email protected]   //*) ///////Begin   Source   function   StringToFile(mString:   string;  

流转换成字符串

public class StreamUtil { /** * 流转换成字符串 * @param is 流对象 * @return 流转换成的字符串 返回null代表异常 */ public static String streamToString(InputStream is) { //1,在读取的过程中,将读取的内容存储值缓存中,然后一次性的转换成字符串返回 ByteArrayOutputStream bos = new ByteArrayOutputStream(); //2,读流操作,读

将二进制流转换成图片文件

import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; /** * 将二进制流转换成图片文件 * * */ public class ImgErToFileUtil { /** * 将接收的字符串转换成图片保存 * @param imgStr 二进制流转

istringstream字符串流,实现类似字符串截取的功能,字符串流中的put,str()将流转换成为字符串string

 1. istringstream字符串流 #include <iostream> #include <sstream> #include <string> using namespace std; struct MyStruct { string str1, str2, str3; double db; int num; char ch; }; void main() { string  mystring("china  google microsoft

php 接收二进制流转换成图片

php 接收二进制流转换成图片,图片类imageUpload.php如下: <?php /** * 图片类 * @author http://blog.csdn.net/haiqiao_2010 * @version 1.0 * * PHP默认只识别application/x-www.form-urlencoded标准的数据类型. * 因此,对型如text/xml 或者 soap 或者 application/octet-stream 之类的内容无法解析,如果用$_POST数组来接收就会失败!

Android将图像转换成流存储与将流转换成图像

1.将图片转换成二进制流 public byte[] getBitmapByte(Bitmap bitmap){ ByteArrayOutputStream out = new ByteArrayOutputStream(); //参数1转换类型,参数2压缩质量,参数3字节流资源 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); try { out.flush(); out.close(); } catch (IOException e

文件转换成二进制流及二进制流转换成文件

原文发布时间为:2008-08-10 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.

JavaScript基础 join() 将数组连接成字符串 化零为整

镇场诗: 清心感悟智慧语,不着世间名与利.学水处下纳百川,舍尽贡高我慢意. 学有小成返哺根,愿铸一良心博客.诚心于此写经验,愿见文者得启发.------------------------------------------ code: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=ut

html 转字符串换成代码

1. [文件] htmlToCode.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http