zoukankan      html  css  js  c++  java
  • 将文本1的内容写入到文本2中

    package com.pdcss.io;

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;

    public class IOTest {

        /**
         * file1>>file2
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
            File infile = new File("D:\1.txt");//这个必须有,自己在里面写点内容
            File outfile = new File("D:\2.txt");//可以没有,会自动建
            FileReader fr = null ;
            FileWriter fw = null;
            try {
                fr = new FileReader(infile);
                fw = new FileWriter(outfile);
                
                BufferedReader br = new BufferedReader(fr);
                BufferedWriter bw = new BufferedWriter(fw);
                
                String line = null;
                String[] oStr = null;
                
                while((line=br.readLine())!= null){
                    bw.write(line+System.getProperty("line.separator"));
                }
                bw.close();
                br.close();
                fw.close();
                fr.close();
                
            } catch (FileNotFoundException e) {
                System.out.println("文件找不到");
                e.printStackTrace();
            } catch (IOException e) {
                System.out.println("写入失败");
                e.printStackTrace();
            }
            System.out.println("写入成功");
        }

    }

  • 相关阅读:
    给下拉框加上可输入查询特性-升级版本
    手把手教你在CentOS7中安装JavaJDK和配置环境变量
    CentOS7.0下MySql的安装和配置
    CentOS常规辅助工具安装
    MongoDB教程之常用操作
    商城商品超卖处理
    微信JS-SDK分享的坑
    当数据库做了Aways on后,收缩数据库日志文件
    SQL Server 2016 非域Aways On环境搭建
    win8以上系统查看iis网站进程内存占用情况
  • 原文地址:https://www.cnblogs.com/hj918/p/3460101.html
Copyright © 2011-2022 走看看