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