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

    }

  • 相关阅读:
    Spring视频学习笔记(一)
    枚举(enum)与类的静态成员(static)
    Java的继承模式
    HTML锁定Table中某一列
    Winform 中的KeyDown
    我的WebService入门
    获取键盘或鼠标多久没有对屏幕进行操作了
    从DB输出值到DataTable时,字段值为NULL时报错相关信息;
    Data层相关问题 & JS循环取值
    字符串String的trim()方法
  • 原文地址:https://www.cnblogs.com/hj918/p/3460101.html
Copyright © 2011-2022 走看看