DIrectory separator pattern
Hi:
I have the following prg that accepts one arg and subsitutes the variable s_var in a file with that arg. Apparently if the arg contains dir separators on windows, the replace pattern does not work. Please help.
public class InstConfig
{
public static void main(String[] args)
{
String dir_sep = System.getProperty("file.separator");
String oh = args[0];
oh = oh.replaceAll("\\","/");
String xmlpConfigLoc = oh +dir_sep+"server-config.xml";
String find_string = "%s_var%";
String old_string ="<" + "file path" + "=" + "\"" + "%s_var%" + "\"" + "/>";
String replacement_string = oh + "/" + "temp";
replacement_string = replacement_string.replaceAll(":", ":/");
String xmlpLine;
FileReader xmlpConfigXml;
BufferedReader xmlpConfigFile;
String new_xmlpLine;
try
{
xmlpConfigXml = new FileReader(xmlpConfigLoc);
xmlpConfigFile = new BufferedReader(xmlpConfigXml);
File xmlpFile = new File(oh + dir_sep+"server-config.xml");
File xmlpNewFile = new File(oh + dir_sep+"server-config1.xml");
BufferedWriter out = new BufferedWriter(new FileWriter(oh + dir_sep+"server-config1.xml"));
while((xmlpLine = xmlpConfigFile.readLine()) != null)
{
new_xmlpLine = xmlpLine.replaceFirst(find_string,replacement_string);
out.write(new_xmlpLine);
out.write("\n");
//break;
}
out.close();
xmlpConfigFile.close();
xmlpFile.delete();
xmlpNewFile.renameTo(xmlpFile);
}
catch (IOException e)
{
}
}
}

