• 字节流字符流及转换


    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 用来使出字符串

  • 相关阅读:
    NO.6: 若不想编译器提供自动生成的函数,就应该明确拒绝
    NO.5: 了解C++编译器默认为你生成的构造/赋值/析构
    NO.4: 确定对象被使用前已被初始化
    NO.3: 尽量使用const
    NO.2: 尽量以const,enum,inline 替换 #define
    NO.1: 视C++为一个语言联邦
    C/C++ exception类
    C/C++ 类成员函数指针 类成员数据指针
    c++中的 Stl 算法(很乱别看)
    自定义类签发校验token-实现多方式登录-自定义反爬类-admin后台表管理字段自定义-群查接口-搜索-排序-分页
  • 原文地址:https://www.cnblogs.com/lgf428/p/5784731.html
Copyright © 2020-2023  润新知