Class ReplaceInFileUtils

java.lang.Object
com.gigaspaces.internal.utils.ReplaceInFileUtils

public class ReplaceInFileUtils extends Object
Using replaceInFile function you need make instance of ReplaceInFileUtils class. Replacing example: ReplaceInFileUtils cli = new ReplaceInFileUtils( fileName ); cli.replaceInFile( "oldStr", "newStr" ); cli.replaceInFile( "oldStr1", "newStr1" ); cli.replaceInFile( "oldStr2", "newStr2" ); cli.close(); You can replace many string in file, at the end you need to close instace of ReplaceInFileUtils object using close() function, it's mean that you don't intresting to replace anymore in this file.
  • Constructor Details

    • ReplaceInFileUtils

      public ReplaceInFileUtils(String fileName) throws IOException
      Constructor of ReplaceInFileUtils.
      Parameters:
      fileName - The file name to replace strings.
      Throws:
      IOException
  • Method Details

    • copyFiles

      public static void copyFiles(String[] files, String destPath) throws IOException
      Coping certain files to destination directory. Example: copy c:/myDir/file.txt c:/myDir/file1.txt c:/myDir/file2.txt c:/destDir
      Throws:
      IOException
    • copyFile

      public static void copyFile(String fileName, String destFileName) throws IOException
      Coping certain file to destination file. Example: copy c:/test/oldFile.txt c:/destDir/newFile.txt
      Throws:
      IOException
    • replaceInFile

      public void replaceInFile(String oldStr, String newStr)
      Find and replace specific characters or words in specic file.
      Parameters:
      oldStr - String to find and replace.
      newStr - New string to replace.
    • replaceInFile

      public void replaceInFile(String oldStr, String newStr, int fromIndex, boolean isOneIteration)
      Find and replace specific characters or words in specific file.
      Parameters:
      oldStr - String to find and replace.
      newStr - New string to replace.
      fromIndex - Started to replace from set index. Start to replace from beginning of file set fromIndex = 1. For example str="igor igor igor best" replaceInFile( "igor", "'replacedStr'", 2, false ); str="igor 'replacedStr' 'replacedStr' best"
      isOneIteration - true replacing will be execute only one time depends fromIndex variable For example str="igor igor igor igor igor best" replaceInFile( "igor", "'replacedStr'", 3, true ); The result is str="igor igor 'replacedStr' igor igor best"
    • xmlReplace

      public void xmlReplace(String propValue, String replacedValue)
      Find and replace specific XML tag value using property value. For example we want to replace specific tag value true to "false" in the following XML example: true Property value for find XML tag will be "com.j_spaces.enabled", replacedValue param will be "false". After replacing, the XML example will be looking: false NOTE: If XML tag not found this method will do nothing!
      Parameters:
      propValue - Property value for find XML tag. For example: com.j_space.enabled
      replacedValue - XML tag value to replace.
    • close

      public void close() throws FileNotFoundException
      Throws:
      FileNotFoundException
    • delTree

      public static void delTree(String dirName, String excludedDirName)
      Recursive utility function that delete entire directory.
      Parameters:
      dirName - Directory to delete.
      excludedDirName - Directory name that will not deleted. Can be null.