2016-02-04 141 views
0

我有了这个路径取代:反斜杠在Java路径

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

,我需要它为options.setBinary。问题是由于反斜杠,我在java中出现错误,但那是我的路径!

我也尝试使用此:

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

但我的命令需要的路径,并发送错误,如果我添加新的字符串

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

我能做些什么?

+0

你有一个正斜杠和反斜杠的路径? –

+1

是的,当我想在我的终端中运行应用程序时,这是我拥有的路径。此外,这是我需要使用在这里说:https://code.google.com/p/selenium/wiki/ChromeDriver – Mxfrd

回答

0

试试这个:

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

修订ANSWER

正如@汤姆和@Erwin Bolwidt评论波纹管路径应为这种改变(对于Mac OS):

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

谢谢!这项工作对我来说:) – Mxfrd

+0

为什么-1投票? 任何人都可以解释这个给我吗? –

+2

我不是选民,但你为什么改变OPs文件路径?他的应用名称是“Google Chrome.app”,您可以在“Google”子目录中将其更改为“Chrome.app”。 – Tom

2

假设你的路径被保存为字符串:

它'因为你的\。尝试用\\替换它,它应该可以工作。

+0

感谢您的帮助,问题解决了! – Mxfrd