java replaceALL 不起作用(url 空格到 %20)

java replaceALL doesn't work (url whitespace to %20)

我的json文件包含白色space如1522663136Vehicle and Bike Procurement Notice 1.PDF。在浏览器中,默认添加 %20。但是在android项目中使用这个文件时,我无法逃脱白色space。我的 json 输出如下。

"heading": "Notice",
"content": "Tender Notice",
"img": "1522663136Vehicle and Bike Procurement Notice 1.PDF"

我正在尝试使用 replaceALL

替换白色 space
String heading = hit.getString("heading");
String content = hit.getString("content");
String pdf = hit.getString("img");
pdf.replaceAll(" ","%20");
String link = "fitandfineindustries.com/images/notices/"+pdf;
mExampleList.add(new ExampleItem(heading, date, content, click, link));

但是不行

在 Java 中,字符串是不可变的,因此替换所有 returns 一个新字符串而不是更改现有字符串。试试这个:

pdf = pdf.replaceAll(" ","%20");