Mxfrd
Mxfrd

Reputation: 43

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 ?

Upvotes: 0

Views: 641

Answers (2)

chalitha geekiyanage
chalitha geekiyanage

Reputation: 6812

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"));

Upvotes: 0

ctst
ctst

Reputation: 1680

Assuming your path is saved as String:

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

Upvotes: 2

Related Questions