List of utility methods to do URL to File Name
String | getFileName(HttpURLConnection conn) get File Name String fileName = conn.getHeaderField("Content-Disposition"); Matcher matcher = REGEX_FILE_NAME.matcher(fileName); if (matcher.find()) { return matcher.group(1); return null; |
String | getFileName(String urlStr) get File Name URL url; try { url = new URL(urlStr); } catch (MalformedURLException ex) { System.err.println("Invalid URL: " + urlStr); assert false; return null; String[] urlParts = url.getPath().split("\\/"); return urlParts[urlParts.length - 1]; |
String | getFilename(String urlString) get Filename String[] urlpaths; try { URL url = new URL(urlString); urlpaths = url.getPath().split("/"); } catch (Exception e) { return null; return urlpaths[urlpaths.length - 1]; ... |
String | getFileName(String urlString) get File Name URL url = null; try { url = new URL(urlString); return new File(url.getFile()).getName(); } catch (MalformedURLException e) { return new File(urlString).getName(); |
String | getFileName(URL extUrl) get File Name String filename = ""; String path = extUrl.getPath(); String[] pathContents = path.split("[\\\\/]"); if (pathContents != null) { int pathContentsLength = pathContents.length; System.out.println("Path Contents Length: " + pathContentsLength); for (int i = 0; i < pathContents.length; i++) { System.out.println("Path " + i + ": " + pathContents[i]); ... |
String | getFileName(URL url) get File Name String s = url.getFile(); return decodeURL(s, "UTF8"); |
String | getFileName(URL url) returns the last element of the URL's path String[] pathElements = url.getPath().split("/"); return pathElements[pathElements.length - 1]; |
String | getFileName(URL url) get File Name return new File(URLDecoder.decode(url.getFile(), "UTF-8")).getName(); |
String | getFileName(URL url) get File Name String fileName = url.getFile(); if (fileName.lastIndexOf('?') != -1) { fileName = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('?')); } else { fileName = fileName.substring(fileName.lastIndexOf('/') + 1); return URLDecoder.decode(fileName); |
String | getFileName(URL url) Returns the file name (without the path) of the resource specified by the given url. return url.getPath().substring(stripResource(url.getPath()).length());
|