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)

{

}

}

}

[1638 byte] By [Nish_Ba] at [2007-11-26 17:09:28]
# 1
I think you need four slashes (two for the Java String, two for the regex).oh = oh.replaceAll("\\\\","/");
doremifasollatidoa at 2007-7-8 23:37:17 > top of Java-index,Java Essentials,Java Programming...
# 2
What about on unix? Do I need any special handling for unix file separators for the oh arg?Thanks.
Nish_Ba at 2007-7-8 23:37:17 > top of Java-index,Java Essentials,Java Programming...
# 3
> What about on unix? Do I need any special handling> for unix file separators for the oh arg?No. A forward slash doesn't need special handling.
doremifasollatidoa at 2007-7-8 23:37:17 > top of Java-index,Java Essentials,Java Programming...