文件上傳 兼容中文文件名 中文亂碼

        //like12 add,20200630,兼容中文文件名
        byte buf[];
        try {
            buf = oldName.getBytes("iso8859-1");
            oldName = new String(buf, "utf-8");
            //System.out.println("兼容中文文件名:" + oldName);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

 

        //中文文件名處理
        String fileNamePre = oldName.substring(0, oldName.indexOf("."));
        System.out.println("編碼前文件名:" + fileNamePre);
        try {
            fileNamePre = URLEncoder.encode(fileNamePre, "UTF-8");
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        System.out.println("編碼後文件名:" + fileNamePre);

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