zoukankan      html  css  js  c++  java
  • Java基础之IO流,文件的复制原理与示例

    import java.io.*;

    class FileCopyDemo
    {
        /*
         * 文件的复制
         
    */
        public static void main(String[] args)
        {
            FileWriter fw = null;
            FileReader fr = null;
            
            try
            {
                fr = new FileReader("d:\\works\\demo.txt");
                fw = new FileWriter("d:\\demo.txt");
                
                char[] buffer = new char[1024];
                int length = 0;
                
                while((length=fr.read(buffer))!=-1)
                {
                    fw.write(buffer,0,length);
                }
            }
            catch(IOException e)
            {
                sop(e.getMessage());
            }
            finally
            {
                try            
                {
                    if(null!=fw) fw.close();
                    if(null!=fr) fr.close();
                }
                catch(IOException e)
                {
                    sop(e.getMessage());
                }
            }
        }
        
        public static void sop(Object obj)
        {
            System.out.println(obj);
        }
    }
  • 相关阅读:
    Python shutil模块
    Flask 上传文件
    Flask DBUtils
    flash-session
    Flash 上下文管理
    python 栈
    python 偏函数
    threding.local
    next() 与 nextLine() 区别
    Thread.sleep(1000*3); // 休眠3秒
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2880971.html
Copyright © 2011-2022 走看看