Java 根据下载链接获取文件名

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,java,url,获取文件名)