zoukankan      html  css  js  c++  java
  • Java基础之IO流,通过字节流对媒体文件进行复制操作

    import java.io.*;

    class ImageCopyDemo
    {
        public static void main(String[] args)
        {
            FileInputStream fis = null;
            FileOutputStream fos = null;
        
            try
            {
                fis = new FileInputStream(new File("001.png"));
                fos = new FileOutputStream(new File("001-copy.png"));
                
                /*
                byte[] buffer = new byte[fis.available()];
                fis.read(buffer);            
                fos.write(buffer);
                
    */
                
                //最折中的方法
                byte[] buffer = new byte[1024];
                int length = 0;
                while((length=fis.read(buffer))!=-1)
                {
                    fos.write(buffer);
                }        
                
                /*
                int ch = 0;
                while((ch=fis.read())!=-1)
                {
                    fos.write(ch);
                }
                
    */
            }
            catch(IOException e)
            {
                System.out.println(e.getMessage());
            }
            finally
            {
                try
                {
                    if(null!=fis)
                        fis.close();
                    if(null!=fos)
                        fos.close();
                }
                catch(IOException e)
                {
                    System.out.println(e.getMessage());
                }
            }
        }
    }
  • 相关阅读:
    Sum Root to Leaf Numbers深度优先计算路径和
    Path Sum II深度优先找路径
    动态和静态链接库
    C/C++变量
    搜索
    基本格式
    随机数生成函数
    珍惜生命,我用Python 。今天开始学习Python
    在windows里hexo 博客创建步骤
    作为一个程序员,什么是脚本。必须要理解
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2886506.html
Copyright © 2011-2022 走看看