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;
}
Java 根据下载链接获取文件名
最新推荐文章于 2024-07-26 03:05:56 发布