我收到以下錯誤RAD:非法字符在索引路徑16
java.net.URISyntaxException: Illegal character in path at index 16: file:/E:/Program Files/IBM/SDP/runtimes/base......
可否請你讓我知道什麼是錯誤以及如何解決它?
我收到以下錯誤RAD:非法字符在索引路徑16
java.net.URISyntaxException: Illegal character in path at index 16: file:/E:/Program Files/IBM/SDP/runtimes/base......
可否請你讓我知道什麼是錯誤以及如何解決它?
索引16處有一個非法字符。我會說它不喜歡路徑中的空間。您可以percent encode空格等特殊字符。在這種情況下用%20替換它。
我聯繫到上述建議採用URLEncoder問題:
String thePath = "file://E:/Program Files/IBM/SDP/runtimes/base";
thePath = URLEncoder.encode(thePath, "UTF-8");
file:///是文件。注意三個 – 2012-05-11 16:04:40
嗯......它並不真正的工作:空間被加號替換,而不是%20,並且所有的斜線也被破壞了...... 請參閱:http://stackoverflow.com/問題/ 4737841/urlencoder-not-translation-space-character – 2012-09-03 21:01:58
我跑進與必應地圖API同樣的事情。 URLEncoder只是讓事情變得更糟,但replaceAll(" ","%20");
伎倆。
安裝目錄不能有空間。 重裝軟件會糾正它
我有一個xml類似的問題。只是通過錯誤和解決方案(編輯Jonathon版本)。
代碼:
HttpGet xmlGet = new HttpGet(xmlContent);
xml格式:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<code>CA</code>
<name>Cath</name>
<salary>300</salary>
</employee>
錯誤:
java.lang.IllegalArgumentException: Illegal character in path at index 0: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contents>
<portalarea>CA</portalarea>
<portalsubarea>Cath</portalsubarea>
<direction>Navigator</direction>
</contents>
at java.net.URI.create(URI.java:859)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
at de.vogella.jersey.first.Hello.validate(Hello.java:56)
不完全完美的解決方案:(該實例消失錯誤)
String theXml = URLEncoder.encode(xmlContent, "UTF-8");
HttpGet xmlGet = new HttpGet(theXml);
任何想法,我應該怎麼做?它剛剛通過,但有問題,而這樣做
HttpResponse response = httpclient.execute(xmlGet);
你試試這個嗎?
new File("<PATH OF YOUR FILE>").toURI().toString();
如果與使用JDK出現此錯誤是:
PROGRA〜1而不是在路徑示例程序文件:
c:/progra~1/java instead of c:/program files/java
這將是確定始終避免用Java代碼空間.....
它可以用於程序文件中的所有東西,否則在開始處加上引號和路徑的英文地址爲
「c:/..../」
今天我得到了這個錯誤,不像以上所有的答案,我的錯誤是由於一個新的原因。
在我的日文翻譯strings.xml文件中,我刪除了必需的字符串。
一些android如何混淆所有其他字符串,並導致錯誤。
解決的辦法是包括所有從我的正常琴絃,英語strings.xml中
包括那些沒有翻譯爲日語字符串。
與空間有相同的問題。 URL和URI的組合解決了這個問題:
URL url = new URL("file:/E:/Program Files/IBM/SDP/runtimes/base");
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
參見[?如何解決路徑此異常非法字符(http://stackoverflow.com/questions/3753852/how-解決這個異常非法字符在路徑) – 2011-02-14 12:51:53
嘗試用'%20'替換空格 – nothrow 2011-02-14 12:52:05
請參閱http://stackoverflow.com/questions/749709/how-to-deal-with上的一般解決方案-the-urisyntaxexception/15570670#15570670 – GKislin 2013-03-22 12:48:43