public class ReplaceInFileUtils extends Object
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 and Description |
---|
ReplaceInFileUtils(String fileName)
Constructor of ReplaceInFileUtils.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
static void |
copyFile(String fileName,
String destFileName)
Coping certain file to destination file.
|
static void |
copyFiles(String[] files,
String destPath)
Coping certain files to destination directory.
|
static void |
delTree(String dirName,
String excludedDirName)
Recursive utility function that delete entire directory.
|
void |
replaceInFile(String oldStr,
String newStr)
Find and replace specific characters or words in specic file.
|
void |
replaceInFile(String oldStr,
String newStr,
int fromIndex,
boolean isOneIteration)
Find and replace specific characters or words in specific file.
|
void |
xmlReplace(String propValue,
String replacedValue)
Find and replace specific XML tag value using property value.
|
public ReplaceInFileUtils(String fileName) throws IOException
fileName
- The file name to replace strings.IOException
public static void copyFiles(String[] files, String destPath) throws IOException
IOException
public static void copyFile(String fileName, String destFileName) throws IOException
IOException
public void replaceInFile(String oldStr, String newStr)
oldStr
- String to find and replace.newStr
- New string to replace.public void replaceInFile(String oldStr, String newStr, int fromIndex, boolean isOneIteration)
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"
public void xmlReplace(String propValue, String replacedValue)
replacedValue
param will be "false". After replacing, the XML example will be looking: propValue
- Property value for find XML tag. For example: com.j_space.enabledreplacedValue
- XML tag value to replace.public void close() throws FileNotFoundException
FileNotFoundException
Copyright © GigaSpaces.