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

  • 相关阅读:
    C++中四大强制类型转换!
    队列(queue)的实现
    栈(stack)的实现
    单向链表
    十种排序算法详解及C++实现
    extern “C”
    C语言内存分配及各种数据存储位置
    Python中的classmethod与staticmethod
    关于ORM,以及Python中SQLAlchemy的sessionmaker,scoped_session
    Python中的SQLAlchemy
  • 原文地址:https://www.cnblogs.com/lgf428/p/5784731.html
Copyright © 2011-2022 走看看