Package com.gigaspaces.internal.utils
Class ReplaceInFileUtils
java.lang.Object
com.gigaspaces.internal.utils.ReplaceInFileUtils
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static voidCoping certain file to destination file.static voidCoping certain files to destination directory.static voidRecursive utility function that delete entire directory.voidreplaceInFile(String oldStr, String newStr) Find and replace specific characters or words in specic file.voidreplaceInFile(String oldStr, String newStr, int fromIndex, boolean isOneIteration) Find and replace specific characters or words in specific file.voidxmlReplace(String propValue, String replacedValue) Find and replace specific XML tag value using property value.
-
Constructor Details
-
ReplaceInFileUtils
Constructor of ReplaceInFileUtils.- Parameters:
fileName- The file name to replace strings.- Throws:
IOException
-
-
Method Details
-
copyFiles
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
Coping certain file to destination file. Example: copy c:/test/oldFile.txt c:/destDir/newFile.txt- Throws:
IOException
-
replaceInFile
Find and replace specific characters or words in specic file.- Parameters:
oldStr- String to find and replace.newStr- New string to replace.
-
replaceInFile
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-truereplacing will be execute only one time dependsfromIndexvariable 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
Find and replace specific XML tag value using property value. For example we want to replace specific tag valuetrue to "false" in the following XML example: Property value for find XML tag will be "com.j_spaces.enabled",true replacedValueparam will be "false". After replacing, the XML example will be looking: NOTE: If XML tag not found this method will do nothing!false - Parameters:
propValue- Property value for find XML tag. For example: com.j_space.enabledreplacedValue- XML tag value to replace.
-
close
- Throws:
FileNotFoundException
-
delTree
Recursive utility function that delete entire directory.- Parameters:
dirName- Directory to delete.excludedDirName- Directory name that will not deleted. Can benull.
-