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("写入成功");
        }

    }

  • 相关阅读:
    其他权益工具
    2股缩为1股
    ubuntu查看网络流量
    修改iphone hosts文件
    Win10 家庭中文版HOST文件更改
    债权投资和其他债权投资的区别
    win10 Administrator没有管理员权限解决方案
    实际发放股票股利
    Could not get lock /var/lib/dpkg/lock
    R语言代写Gibbs抽样的贝叶斯简单线性回归仿真分析
  • 原文地址:https://www.cnblogs.com/hj918/p/3460101.html
Copyright © 2011-2022 走看看