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

    }
    }

     
  • 相关阅读:
    MySQL链接超时的解决办法
    使用Axis开发Web Service程序
    Linux动态库(.so)搜索路径
    MYSQL性能调优简述
    什么是AXIS
    巧夺天工的kfifo
    双离合DSG
    实例讲解C# WebService
    如何为 MySQL 选择更合适的服务器硬件
    7 MySQL 事务与锁定命令
  • 原文地址:https://www.cnblogs.com/lev1/p/11297757.html
Copyright © 2011-2022 走看看