编码转换统一防止乱码

    public static void main(String[] args) throws UnsupportedEncodingException {
        String origin = new String("元字符".getBytes(StandardCharsets.UTF_8), "iso8859-1");
        String fileName1 = new String(origin.getBytes("iso8859-1"), "utf-8");
        String fileName2 = URLDecoder.decode(URLEncoder.encode(origin, "iso8859-1"), "utf-8");
        String encodeTo = URLEncoder.encode(origin, "utf-8");
        String encode = URLEncoder.encode(origin, "iso8859-1");
        String encodeUtf8 = URLEncoder.encode("元字符", "utf-8");
        String decode = URLDecoder.decode(origin, "iso8859-1");
        System.out.println(encode);
        System.out.println(decode);
        // System.out.println(fileName1.equals(fileName2));
        // 结果为true
    }

posted @   liftsail  阅读(10)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示