1 import java.io.*; 2 3 public class FileSearchReplace { 4 5 public static void main(String [] args) throws IOException { 6 int argc = 0; 7 8 if (args.length == 0) { 9 System.out.println("Utility to update file contents using simple search/replace strings"); 10 System.out.println("Usage: FileSearchReplace <filename> {<searchstr> <replacestr>}"); 11 System.exit(0); 12 } 13 14 String filename = args[argc++]; 15 String fileContents = Utility.loadFile(filename); 17 18 while (argc < args.length) { 19 String searchStr = args[argc++]; 20 String replaceStr = args[argc++]; 21 23 fileContents = Utility.replace(fileContents, searchStr, replaceStr); 24 } 25 26 Utility.saveFile(filename, fileContents); 28 } 29 30 } 31 | Popular Tags |