zoukankan      html  css  js  c++  java
  • IO流_字节流

    IO流_字节流

    /**
     * 一、流的分类:
     * 1.操作的数据单位:字节流、字符流
     * 2.数据的流向:输入流、输出流
     * 3.流的角色:节点流、处理流
     *
     * 二、流的体系结构
     * 抽象基类             节点流(或文件流)            缓冲流(处理流的一种)
     * InputStream         FileInputStream           BufferedInputStream
     * OutputStream        FileOutputStream          BufferedOutputStream
     * Reader              FileReader                BufferedReader
     * Writer              FileWriter                BufferedWriter
     */
    

    FileInputStreamAndOuputStream

    • 使用字节流FileInputStreamch处理文本文件,可能出现乱码

    • FileInputStreamAndOuputStream读写非文本文件

      示例代码:

    /*
    实现对图片的复制操作
     */
    public class testIOStream {
        public static void main(String[] args){
            FileInputStream fileInputStream = null;
            FileOutputStream fileOutputStream = null;
            try {
                //造文件
                File src = new File("基础语法\沙滩.jpg");
                File dest = new File("基础语法\沙滩2.jpg");
                //造流
                fileInputStream = new FileInputStream(src);
                fileOutputStream = new FileOutputStream(dest);
                //复制过程
                byte[] buffer = new byte[5];
                int len;
                while ((len = fileInputStream.read(buffer)) != -1){
                    fileOutputStream.write(buffer,0,len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                //关闭操作
                try {
                    if (fileInputStream != null)
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    if (fileOutputStream != null)
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
            }
        }
    }
    
    
  • 相关阅读:
    python3给socket模块设置代理
    yield、greenlet与协程gevent
    线程池
    并发通信、生产者与消费者模型
    多进程和多线程
    非阻塞套接字与IO多路复用
    14.python模块之subprocess
    判断页面是否滑到底部
    @vue/cli 3.x 版本配置productionGzip提高性能
    vue跳转到指定位置
  • 原文地址:https://www.cnblogs.com/qiudajiang/p/13274106.html
Copyright © 2011-2022 走看看