首页 > 其他分享 >Content-Disposition文件名乱码转码问题

Content-Disposition文件名乱码转码问题

时间:2023-01-20 12:11:50浏览次数:48  
标签:Content String 转码 文件名 fileName 乱码 Disposition uc

public String getFileName(String urlStr){
        String fileName = null;
        try {
            URL url = new URL(urlStr);
            URLConnection uc = url.openConnection();
            fileName = uc.getHeaderField("Content-Disposition");
            fileName = new String(fileName.getBytes("ISO-8859-1"), "GBK");
            fileName = URLDecoder.decode(fileName.substring(fileName.indexOf("filename=")+9),"UTF-8");
            log.info("文件名为:" + fileName + "  大小" + (uc.getContentLength()/1024)+"KB");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fileName;
    }

 

标签:Content,String,转码,文件名,fileName,乱码,Disposition,uc
From: https://www.cnblogs.com/yinliang/p/17062641.html

相关文章