Java 異常 獲取類路徑 中文亂碼

 

// 獲取classpath的絕對值路徑,有中文需要解碼路徑,不然輸出的是亂碼的
private static String basePath;
static {
    try {
        basePath = URLDecoder.decode(Thread.currentThread().getContextClassLoader().getResource("").getPath(),"UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}

參考鏈接:https://blog.csdn.net/yuhaiqiang_123/article/details/51288456

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章