• 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);
        }
    }
  • 相关阅读:
    熟悉常用的Linux操作
    Hadoop综合大作业
    理解MapReduce
    熟悉常用的Hbase操作
    第三章 熟悉常用的HDFS操作
    爬虫大作业
    数据结构化与保存
    爬取校园新闻首页的新闻
    网络爬虫基础练习
    综合练习:词频统计
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2880971.html
Copyright © 2020-2023  润新知