gpt4 book ai didi

java - 什么是文件 ://protocol url encodings for these special characters(; $ % ^ #)

转载 作者:行者123 更新时间:2023-11-30 11:05:07 26 4
gpt4 key购买 nike

我遇到过图像文件包含特殊字符的情况,例如 $ % ^ #。为了在 xmlworker 生成的 pdf 上显示这些图像,需要对这些图像进行 URL 编码。

我们使用 file:// 协议(protocol)将图像放在 xmlworker 生成的 pdf 上,而不是 https://http://协议(protocol)。

请为 file:// 协议(protocol) url 的以下字符提供等效的 URL 编码。

  1. #
  2. $
  3. %
  4. &
  5. +

最佳答案

你试过 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com