解决异常 java.net.URISyntaxException: Illegal character in query at index

02-29 阅读 0评论

java.net.URISyntaxException 表示你在尝试创建一个 URI 对象时,传递了一个非法的 URI 字符串

解决异常 java.net.URISyntaxException: Illegal character in query at index,解决异常 java.net.URISyntaxException: Illegal character in query at index,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,方法,创建,第1张
(图片来源网络,侵删)

这个异常通常是因为 URI 字符串中包含了不合法的字符,比如空格、特殊字符等。在 URI 中,某些字符是需要进行编码的,例如空格会被编码为 %20。

要解决这个异常,亲测以下几个方法

检查 URI 字符串:仔细检查你传递给 new URI() 构造函数的字符串,确保其中不包含非法字符。

对 URI 进行编码:如果 URI 字符串中包含了特殊字符或空格,你可以使用 Java 提供的 URLEncoder 类对它们进行编码,然后再传递给 new URI()。

String urlString = "https://example.com/page with space";
String encodedUrlString = URLEncoder.encode(urlString, "UTF-8");
URI uri = new URI(encodedUrlString);

使用 URL 类:如果你只需要对 URL 进行简单的操作,你可以考虑使用 URL 类,它对 URL 进行了更高层次的封装,并提供了一些方便的方法。

URL url = new URL("https://example.com/page with space");
解决异常 java.net.URISyntaxException: Illegal character in query at index,解决异常 java.net.URISyntaxException: Illegal character in query at index,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,方法,创建,第2张
(图片来源网络,侵删)
解决异常 java.net.URISyntaxException: Illegal character in query at index,解决异常 java.net.URISyntaxException: Illegal character in query at index,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,方法,创建,第3张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]