• I/O流的学习


    一.I/O流

      1.判定是输入还是输出我们应该站在程序的立场;

      2.判断传输的是字节还是字符,从而决定管道的大小,字节传递是根本,可以传递所有的数据类型,字符传递专门用来传递文本数据,字节主要用来传递二进制数据。

      3.Java流的四大父类:

        ①字节流Inputstream和Outputstream

        ②字符流Reader 和 Writer

    二.主要的使用文件的拷贝

     例:

    package com.lovo.test;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    
    public class TestStream {
        public static void main(String[] args) {//功能:将D:/test.avi  拷贝到  F:/wudi.avi
            FileInputStream fis = null;
            FileOutputStream fos = null;
            try {
                //1、建立管道
                fis = new FileInputStream("D:/test.avi");
                fos = new FileOutputStream("F:/wudi.avi");
                
                //2、操作管道
                byte[] b = new byte[1024];
                int length = 0;//记录读取了多少个有效字节数
                while((length = fis.read(b)) != -1){
                    fos.write(b,0,length);
                    fos.flush();//强制刷出缓冲区的内容
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally{
                //3、关闭管道
                if(fis != null){
                    try {
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(fos != null){
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  • 相关阅读:
    点击文本变成输入框
    html代码片段
    node 开启Gzip压缩
    npm 安装与卸载
    console.dir()-----js中console.log()和console.dir()的区别
    javaScript学习笔记之-------this
    javaScript学习笔记之-------闭包
    从零搭建vue项目---VUE从无到有
    require.js扫盲版
    cross-env 解决跨平台设置的NODE_ENV的问题
  • 原文地址:https://www.cnblogs.com/qq1083735206/p/6242252.html
Copyright © 2020-2023  润新知