001 package com.croftsoft.apps.text;
002
003 import java.io.*;
004
005 import com.croftsoft.core.io.FileLib;
006
007 /*********************************************************************
008 * Replaces text in a file.
009 *
010 * <P>
011 *
012 * Command line:<BR>
013 * java com.croftsoft.apps.text.ReplaceText fileName oldString newString
014 *
015 * <P>
016 *
017 * @version
018 * 1999-08-15
019 * @author
020 * <A HREF="http://www.alumni.caltech.edu/~croft/">David W. Croft</A>
021 *********************************************************************/
022
023 public class ReplaceText
024 //////////////////////////////////////////////////////////////////////
025 //////////////////////////////////////////////////////////////////////
026 {
027
028 public static void main ( String [ ] args )
029 throws FileNotFoundException, IOException
030 //////////////////////////////////////////////////////////////////////
031 {
032 if ( args.length != 3 )
033 {
034 System.out.println ( "java com.orbs.app.util.ReplaceText "
035 + "fileName oldString newString" );
036 return;
037 }
038 replaceText ( args [ 0 ], args [ 1 ], args [ 2 ] );
039 }
040
041 /*********************************************************************
042 * Calls FileLib.replaceStrings(file, oldString, newString).
043 *********************************************************************/
044 public static void replaceText (
045 String fileName, String oldString, String newString )
046 throws FileNotFoundException, IOException
047 //////////////////////////////////////////////////////////////////////
048 {
049 File file = new File ( fileName );
050 System.out.print ( file.getCanonicalPath ( ) + " " );
051 System.out.println (
052 FileLib.replaceStrings ( file, oldString, newString )
053 ? "changed" : "unchanged" );
054 }
055
056 //////////////////////////////////////////////////////////////////////
057 //////////////////////////////////////////////////////////////////////
058 }