• 替换文本文件内容


    
    

    package cn.home;

    
    

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;

    
    

    public class Replace {
    public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream("F:\javaclasszjl\test.txt");
    InputStreamReader isr = new InputStreamReader(fis);
    BufferedReader br = new BufferedReader(isr);
    FileOutputStream fos = new FileOutputStream("F:\javaclasszjl\abc.txt");
    OutputStreamWriter osw = new OutputStreamWriter(fos);
    BufferedWriter bw = new BufferedWriter(osw);
    String s1 = "";
    String s2 = "";
    System.out.print("替换前:");
    while((s1 = br.readLine())!=null) {
    System.out.println(s1);
    s2 = s1;
    }
    s2 = s2.replace("{name}", "小黑");
    s2 = s2.replace("{type}", "狗狗");
    s2 = s2.replace("{master}", "张丹");
    System.out.print("替换后:");
    bw.write(s2);
    System.out.println(s2);

    bw.close();
    osw.close();
    fos.close();
    br.close();
    isr.close();
    fis.close();

    }
    }

     
  • 相关阅读:
    redis存储session配制方法
    thanks使用注意事项;
    mongodb sort limit和skip用法
    mongoose的用法(注:连接数据库)
    mongoose查询特定时间段文档的方法
    webworker的使用案例
    js 传参数
    redis.config翻译
    Oracle keep详解
    自学之笔记总结
  • 原文地址:https://www.cnblogs.com/lev1/p/11297757.html
Copyright © 2020-2023  润新知