java文件下载如何保留特殊字符

xiaoxiao2022-05-13  27

public class URLEncoderUtils { private static final String regex = "[^!#$%&'()*+,./;:=?@[/] ]"; public static String encode(String str, String charset) throws UnsupportedEncodingException { if (str == null || charset == null) { return ""; } StringBuffer sb = new StringBuffer(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(str); while (matcher.find()) { matcher.appendReplacement(sb, URLEncoder.encode(matcher.group(0), charset)); } matcher.appendTail(sb); return sb.toString(); } }
转载请注明原文地址: https://www.6miu.com/read-4884178.html

最新回复(0)