文本替换工具.java

开发中常常遇到需要重复复制,粘贴的场景。浪费大量时间,效率低下,容易出错,没有意义。简单排版,告别大量copy,paste.
开发工具:Ultra Edit排版,型如:{"《红楼梦》","《西游记》","《水浒传》","《三国演义》"},常用方法:列模式,ctrl+r替换等。
         IntelliJ IDEA or eclipse
import java.io.*;

public class ReplaceJava {


        public static void main(String[] args) throws IOException {

            String [] s = new String []{"《红楼梦》","《西游记》","《水浒传》","《三国演义》"};
            StringBuffer buffer = new StringBuffer();
            for(String s1:s){
                replace(s1);
                buffer.append(replace(s1));
            }
            outPut(buffer.toString());

        }
        /**
         * output by console*/
        public static String replace(String repacebywhat){
            String model =     "<file>\n" +
                    "            <note>bookname:@replace@</note>\n" +
                    "        </file>";
            String result = model.replaceAll("@replace@",repacebywhat);
            System.out.println(result);
            return result;
        }
    /**
     * output by txt file*/
        public static void outPut(String s) throws IOException {
            String fileOutPath="D:/result.txt";
            FileOutputStream fos=new FileOutputStream(fileOutPath);
            OutputStreamWriter osw=new OutputStreamWriter(fos,"UTF-8");
            BufferedWriter bw=new BufferedWriter(osw);
            bw.write(s);
            bw.flush();//刷新txt
            bw.close();
            osw.close();
            fos.close();
            System.out.println("txt文件已生成内容");

        }

}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值