用于为URLDecoder.decode()抛出UnsupportedEncodingException的示例字符串

时间:2019-01-11 12:34:23

标签: java exception encoding

有人可以建议一个示例字符串(sampleString的值)进行获取
下面的给定代码段中的UnsupportedEncodingException

public static String decode(String sampleString)  
{  
    try {   
         return URLDecoder.decode(sampleString, "UTF-8" );  
    } catch (UnsupportedEncodingException e) {  
         return "Issue while decoding" +e.getMessage();  
    }  
}

2 个答案:

答案 0 :(得分:1)

直接从URLDecoder.decode(String,String)的实现

if (enc.length() == 0) {
        throw new UnsupportedEncodingException ("URLDecoder: empty string enc   parameter");
}

所以

URLDecoder.decode(sampleString, "" );  

引发异常。

答案 1 :(得分:0)

UEE仅适用于编码/字符集恕我直言URLDecoder.decode(sampleString, "DOS"),其中编码“ DOS”不可用。唯一的问题可能是错误的%编码。 U + 2015(水平栏)将为%E2%80%95,可能会写为%95(连续字节)。 “”用于编码肯定会给出UUE。