zoukankan      html  css  js  c++  java
  • 替换文本文件内容

    
    

    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();

    }
    }

     
  • 相关阅读:
    PAT 甲级 1115 Counting Nodes in a BST (30 分)
    PAT 甲级 1114 Family Property (25 分)
    PAT 甲级 1114 Family Property (25 分)
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
  • 原文地址:https://www.cnblogs.com/lev1/p/11297757.html
Copyright © 2011-2022 走看看