package Chapter8;import java.io.*;import java.util.*;public class ReplaceText {public static void main(String[] args) throws Exception {// Check command line parameter usageif (args.length != 4) {System.out.println("Usage: java ReplaceText sourceFile targetFile oldStr newStr");System.exit(0);}// Check if source file existsFile sourceFile = new File(args[0]);if (!sourceFile.exists()) {System.out.println("Source file " + args[0] + " does not exist");System.exit(0);}// Check if target file existsFile targetFile = new File(args[1]);if (targetFile.exists()) {System.out.println("Target file " + args[1] + " already exists");System.exit(0);}// Create input and output filesScanner input = new Scanner(sourceFile);PrintWriter output = new PrintWriter(targetFile);while (input.hasNext()) {String s1 = input.nextLine();String s2 = s1.replaceAll(args[2], args[3]);output.println(s2);}input.close();output.close();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。