【问题标题】:URI not absolute when filename contains spaces当文件名包含空格时 URI 不是绝对的
【发布时间】:2015-09-15 21:32:23
【问题描述】:

使用 URI,我想返回文件的路径,但是我遇到了空格问题(URI 不是绝对的),为了解决这个问题,我找到了 URLEncoder.Encode。

我需要对下面的代码使用编码:

new File(new URI(Path)).getAbsolutePath();

【问题讨论】:

    标签: java file encoding uri


    【解决方案1】:

    如果没有其他非法字符,只需替换空格即可。

    new File(new URI(Path.replaceAll(" ", "%20"))).getAbsolutePath();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 2022-10-15
      • 2011-11-20
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多