java - Replace backslash with forward slash -
this question has answer here:
- string not replacing characters 4 answers
- how replace backward slash forward slash using java? 3 answers
i have following path: com/teama/merc/test/restest
, want convert this: com\teama\merc\test\restest
i trying append above path path: c:\users\toby\git\mercury\mercury\
str.replace('/', '\\');
when append both of strings together, output: c:\users\toby\git\mercury\mercury\com/teama/merc/test/restest
here code in question:
string home = system.getproperty("user.dir"); path.replace('/', '\\'); system.out.println(path); string folder = home + file.separatorchar + path; system.out.println(folder); file file = new file(folder); if(file.isdirectory()) { system.out.println(file.getpath() + " directory"); }
the appended path not seen folder because of slashes. help?
edit: clarify, full path (both strings appended) infact folder.
in java, string's aren't mutable, when change them replace method, have reassign variable changed string. so, have change replace code this:
path = path.replace('/', '\\');
Comments
Post a Comment