![](/img/trans.png)
[英]java.io.IOException: Cannot run program “…”: java.io.IOException: error=2, No such file or directory
[英]Cannot run program java.io.IOException
我正在嘗試在此代碼中打開Chrome 。 但是由於無法運行程序“ C:/ Program”錯誤,我無法這樣做。 請幫幫我!
public class chrome
{
public static void main(String args[])throws Exception
{
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Google\\Chrome\\chrome.exe");
}
}
我使用雙反斜杠來轉義一個反斜杠,因為反斜杠是轉義字符。
使用路徑構建路徑
Process p = Runtime.getRuntime().exec(Paths.get("C:", "Program Files", "Google",
"Chrome", "chrome.exe").toString());
您可以改用ProcessBuilder:
Process p = new ProcessBuilder("C:\\Program Files\\Google\\Chrome\\chrome.exe").start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.