开发中常常遇到需要重复复制,粘贴的场景。浪费大量时间,效率低下,容易出错,没有意义。简单排版,告别大量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文件已生成内容"); } }
文本替换工具.java
最新推荐文章于 2024-08-01 16:55:00 发布