zoukankan      html  css  js  c++  java
  • (转)Java InputStream、String、File相互转化 --- good

    String --> InputStream
    ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());

    InputStream --> String
    String inputStream2String(InputStream is){
       BufferedReader in = new BufferedReader(new InputStreamReader(is));
       StringBuffer buffer = new StringBuffer();
       String line = "";
       while ((line = in.readLine()) != null){
         buffer.append(line);
       }
       return buffer.toString();
    }


    File --> InputStream

    InputStream in = new FileInputStream(file);

    InputStream --> File

    public void inputstreamtofile(InputStream ins,File file){
       OutputStream os = new FileOutputStream(file);
       int bytesRead = 0;
       byte[] buffer = new byte[8192];
       while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
          os.write(buffer, 0, bytesRead);
       }
       os.close();
       ins.close();
    }

    http://blog.sina.com.cn/s/blog_a000da9d010121bl.html

  • 相关阅读:
    京东精益敏捷教练分享:敏捷助力产品创新!
    设计规范 | 详解组件控件结构体系
    Axure响应式进阶
    通讯录表设计
    TEST1
    c#练习四单元总结
    窗体控件应用总结(1)
    .NET(c#理解)
    test2-11
    test1-1
  • 原文地址:https://www.cnblogs.com/ZJ0065/p/10700685.html
Copyright © 2011-2022 走看看