下載地址url中帶有中文是url轉換方法
阿新 • • 發佈:2019-02-08
方法1 import org.springframework.web.util.UriUtils;//用spring工具
String remotetest =UriUtils.encodePath(remoteFilePath, "UTF-8");
System.out.println(remotetest);方法2, String[] ss= remoteFilePath.split("/"); //自己對url拆分URLEncoder.encode()轉換拼接
String[] ssend= new String[ss.length];
for (int i=0; i<ss.length;i++ ) {
if (i>2) {
ssend[i] ="/"+URLEncoder.encode(ss[i],"UTF-8") ;
}else{
ssend[i] ="/"+ss[i];
}
}
String newstr="";
for (int i=0;i<ssend.length;i++) {
// if(i==2) {
// continue;
// }
newstr +=ssend[i].trim();
}
System.out.println(newstr.substring(1));