• day24每日一考


    day24每日一考

    题目

    1.说明流的三种分类方式
    2.写出4个IO流中的抽象基类,4个文件流,4个缓冲流
    3.字节流与字符流的区别与使用情境
    4.使用缓冲流实现a.jpg文件复制为b.jpg文件的操作
    5.转换流是哪两个类,分别的作用是什么?请分别创建两个类的对象。

    答案

    1

    按流的数据单位分:字节流、字符流

    按流向分:输入流、输出流

    按流角色:节点流、处理流

    2

    Reader Writer InputStream OutputStream

    FileReader FileWriter FileInputStream FileOutputStream

    BufferedReader BufferedWriter BufferedInputStream BufferedOutputStream

    3

    字节流的数据是以字节为单位进行传输,非文本文件

    字符流的数据是以字符为单位进行传输,文本文件

    4

    public class Demo1 {
        public static void main(String[] args) {
            FileInputStream fileInputStream = null;
            FileOutputStream fileOutputStream = null;
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                fileInputStream = new FileInputStream("123.jpg");
                fileOutputStream = new FileOutputStream("jqk.jpg");
                bis = new BufferedInputStream(fileInputStream);
                bos = new BufferedOutputStream(fileOutputStream);
                byte[] bytes = new byte[10];
                int len;
                while ((len = bis.read(bytes)) != -1) {
                    bos.write(bytes, 0, len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (bis != null) {
                    try {
                        bis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (bos != null) {
                    try {
                        bos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    5

    InputStreamReader:将输入的字节流转换为字符流。解码,构造器里面可以指定编码类型,也可以默认,要与源文件一致

    OutputStreamWriter:将输出的字符流转换为字节流。编码,构造器里面可以指定编码类型,也可以默认

  • 相关阅读:
    [极客大挑战 2020]
    系统性能测试工具
    车载电子电器架构 —— 车辆模式管理
    FL Studio21傻瓜式编曲音乐编辑器FL水果软件
    [附源码]SSM计算机毕业设计江苏策腾智能科技公司人事管理系统JAVA
    Python3 面向对象,一篇就够了
    精品基于NET实现的汽配网上商城系统
    关于 Python 的 import
    5. 【哈夫曼树】定义、构造、编码
    ansible及其模块
  • 原文地址:https://blog.csdn.net/m0_47711130/article/details/126159298