zoukankan      html  css  js  c++  java
  • 输入输出流String间的转换

    来自:http://wuhongyu.iteye.com/blog/806791

    1.String  to  inputStream

    InputStream is = new ByteArrayInputStream(string.getBytes());  
    

      

    2.InputStream to String

          

    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    int i;  
    while ((i = is.read()) != -1) {  
        baos.write(i);  
    }  
    String str = baos.toString();  
    System.out.println(str); 
    

     3.String写入OutputStream

    OutputStream os = System.out;  
    os.write(string.getBytes());
    

     4.OutputStream写入String

    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    //向OutPutStream中写入,如 message.writeTo(baos);  
    String str = baos.toString(); 
    

      

     

  • 相关阅读:
    Grails
    Grails
    Grails
    Grails
    Grails
    Grails
    PG
    TopShelf安装多实例
    Js 实现自定义事件
    HttpContext未null处理
  • 原文地址:https://www.cnblogs.com/height/p/3247805.html
Copyright © 2011-2022 走看看