zoukankan      html  css  js  c++  java
  • 字节输入输出流

    package com.sxt.copy1;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    
    /*
     * 字节输入输出流
     * InputStream
     * OutputStream
     * 实现Copy文件操作
     */
    public class TestBCopy {
        public static void main(String[] args){
            InputStream is = null;
            OutputStream os = null;
            try {
                //输入流
                is = new FileInputStream("F:\01_面向对象设计思想_重要_1.avi");
                //输出流
                os = new FileOutputStream("G:\CopyDest.avi");
                //新建字节数组
                byte[] b = new byte[1024];
                //第一步:读取文件到程序
                int len = 0;
                while((len = is.read(b)) != -1){//读取文件到数组 同时返回数据长度
                    System.out.println(len);
                    os.write(b, 0, len);//第二步:再从程序读到文件   System.arraycopy
                }
                System.out.println("Copy操作完成!");
                
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally{
                if(is != null){//确定流打开再关闭
                    try {
                        is.close();//关闭流
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if(os != null){
                    try {
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
  • 相关阅读:
    bryce1010的图像处理课程设计
    linux常用命令
    linux自动连接校园网设置
    LoadRunner12学习之路(6-8)
    LoadRunner12学习之路(1-5)
    Windows软件推荐
    LoadRunner_11破解教程完整版
    linux的SHELL编程
    菜鸡CodeFoces打卡单
    21天记完托福单词打卡
  • 原文地址:https://www.cnblogs.com/qingfengzhuimeng/p/6764146.html
Copyright © 2011-2022 走看看