zoukankan      html  css  js  c++  java
  • 字节流字符流及转换

    11111,字符流用法
                  byte[] bytes = new byte[1024 * 8];

                int lenth = 0;//每次读取到的数据的个数
                //开始循环
                while ((lenth = inputStream.read(bytes)) != -1) {
                count++;
                System.out.println(lenth);
              System.out.println(new String(bytes, 0, lenth));
            }
    详细代码介绍 http://www.cnblogs.com/liuling/archive/2013/05/08/bufferedStream.html
    22222222,字节流用法
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
               //声明一个string字符串,可变字符串。
               StringBuffer buffer = new StringBuffer();
               String line = "";
               while ((line = reader.readLine()) != null) {
              buffer.append(line);
                }
                System.out.println(buffer);
    33333333//字节流字符流区别和转换
               URL url = new URL(path);
              //建立一个和当前URL相关的连接
                URLConnection connection =url.openConnection() ;//返回一个URLConnection对象
                 InputStream inputStream = connection.getInputStream();//得到一个字节流对象
                //InputStream inputStream=new FileInputStream(connection) ;//字节流
                 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));//字符流,InputStreamReader字节流转为字符流

             new InputStreamReader(inputStream));字节流转为字符流的通道!

    444444444//字节流字符流读取数据方式
                字节流,字符流,字节流一次读到一个字节8位,字符流,每次读到一个字符,两个字节或三个字节(16,24)
               字节流不适合读文本,容易乱码,(当每次读到为单数时如5个字节,当读汉字时为两个字节,第三个字就乱码了
                )
                 字符串转为字符输出,tochararray
                tostring 用来使出字符串

  • 相关阅读:
    NPOI读取excel表,如果有公式取出的是公式,想要取数字怎么办?
    win7 64位安装redis 及Redis Desktop Manager使用
    .net实现md5加密 sha1加密 sha256加密 sha384加密 sha512加密 des加密解密
    用户、角色、权限数据库设计
    C#实现手机发送验证码
    遍历页面上的checkbox
    Http简介
    HTTP深入浅出 http请求
    最好用的js前端框架、组件、文档在线预览插件
    windows下nginx安装、配置与使用
  • 原文地址:https://www.cnblogs.com/lgf428/p/5784731.html
Copyright © 2011-2022 走看看