how to change file path d:\test.txt to d:\\test.txt

i am getting error for file path
sunda2010Asked:
Who is Participating?
 
dinhchung82Connect With a Mentor Commented:
Hi ,

I think it is usefull for you :

The Java String class has several methods that allow you to perform an operation using a regular expression on that string. One is replaceAll(String regex, String replacement) that take strings as arguments. Java string use the literal string "\\" for single backslash and in regular expression, the "\\" matches a single backslash too. This make [the regular expression as java string] single backslash becomes "\\\\". e.g. If you have a string "c:\test\test2\" and want to change to "c:/test/test2/", your code should look like:

class Bsl{
   public static void main(String args[]){
      String s="c:\\test\\test2";
      String foreslash="/";
      String regex="\\\\";
      System.out.println(s.replaceAll(regex,foreslash));
   }
}


result:

$ java Bslc:/test/test2$

Regards,
VDC



0
 
Gurvinder Pal SinghCommented:
0
 
Gurvinder Pal SinghCommented:
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
a_bCommented:
Change that to - "d:/test.txt" easiest.
0
 
J KCommented:
try this
path.replaceAll("\","\\");
0
 
Gurvinder Pal SinghCommented:
@jalpa_144: path.replaceAll("\","\\"); will give compilation error
0
 
a_bCommented:
If you are using an IDE just do a replace - ':\' with ':/'
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.