我遇到过图像文件包含特殊字符的情况,例如 $ % ^ #
。为了在 xmlworker 生成的 pdf 上显示这些图像,需要对这些图像进行 URL 编码。
我们使用 file://
协议(protocol)将图像放在 xmlworker 生成的 pdf 上,而不是 https://
或 http://
协议(protocol)。
请为 file://
协议(protocol) url 的以下字符提供等效的 URL 编码。
- #
- $
- %
- &
- +
最佳答案
你试过 URLEncoder 吗;
String url = "file://=" + URLEncoder.encode("#aaaaa$bbbb%cccc&ddd+eeee", "UTF-8");
输出;
file://=%23aaaaa%24bbbb%25cccc%26ddd%2Beeee
和网址解码器;
String url = URLDecoder.decode("file://=%23aaaaa%24bbbb%25cccc%26ddd%2Beeee", "UTF-8");
输出
file://=#aaaaa$bbbb%cccc&ddd+eeee
关于java - 什么是文件 ://protocol url encodings for these special characters(; $ % ^ #),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749530/