简体   繁体   中英

Backslash replace in a java path

I've got this path :

 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

And I need it for a options.setBinary . The problem is that I've got an error in my java due to the backslash, but that's my path!

I also try to use this :

 String newString = text.replace(...);

But my command needs a path and sends error if I add new string

 options.setBinary(" /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome ");

What can I do ?

Assuming your path is saved as String:

It's because of your \\ . Try replacing it with \\\\ , and it should work.

Try this one:

 options.setBinary(new File("/Applications/Google/Chrome.app/Contents/MacOS/Google/Chrome"));

UPDATED ANSWER

As @Tom and @Erwin Bolwidt commented bellow path should change as this (for mac os):

options.setBinary(new File("/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM