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());
                }
            }
        }
    }
  • 相关阅读:
    poj 2528 Mayor's posters (线段树+离散化)
    poj 1201 Intervals (差分约束)
    hdu 4109 Instrction Arrangement (差分约束)
    poj 1195 Mobile phones (二维 树状数组)
    poj 2983 Is the Information Reliable? (差分约束)
    树状数组 讲解
    poj 2828 Buy Tickets (线段树)
    hdu 1166 敌兵布阵 (树状数组)
    Ubuntu网络配置
    Button控制窗体变量(开关控制灯的状态)
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2886506.html
Copyright © 2011-2022 走看看