[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

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

i am getting error for file path
0
sunda2010
Asked:
sunda2010
1 Solution
 
Gurvinder Pal SinghCommented:
0
 
Gurvinder Pal SinghCommented:
0
 
a_bCommented:
Change that to - "d:/test.txt" easiest.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jalpa KotakCommented:
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
 
dinhchung82Commented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now