Consider using Spring's Resource abstraction in the core package
for handling all kinds of file resources in a uniform manner.
org.'s getResource()
method can resolve any location to an org.
object, which in turn allows one to obtain a java.io.File in the
file system through its getFile() method.
org.springframework.core.io.Resource , org.springframework.core.io.ClassPathResource , org.springframework.core.io.FileSystemResource , org.springframework.core.io.UrlResource , org.springframework.core.io.ResourceLoader
| Modifier and Type | Field and Description |
|---|---|
| public static final String | CLASSPATH_URL_PREFIX
Pseudo URL prefix for loading from the class path: "classpath:". |
| public static final String | FILE_URL_PREFIX
URL prefix for loading from the file system: "file:". |
| public static final String | JAR_FILE_EXTENSION
File extension for a regular jar file: ".jar". |
| public static final String | JAR_URL_PREFIX
URL prefix for loading from a jar file: "jar:". |
| public static final String | JAR_URL_SEPARATOR
Separator between JAR URL and file path within the JAR: "!/". |
| public static final String | URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file". |
| public static final String | URL_PROTOCOL_JAR
URL protocol for an entry from a jar file: "jar". |
| public static final String | URL_PROTOCOL_VFS
URL protocol for a general JBoss VFS resource: "vfs". |
| public static final String | URL_PROTOCOL_VFSFILE
URL protocol for a JBoss file system resource: "vfsfile". |
| public static final String | URL_PROTOCOL_VFSZIP
URL protocol for an entry from a JBoss jar file: "vfszip". |
| public static final String | URL_PROTOCOL_WAR
URL protocol for an entry from a war file: "war". |
| public static final String | URL_PROTOCOL_WSJAR
URL protocol for an entry from a WebSphere jar file: "wsjar". |
| public static final String | URL_PROTOCOL_ZIP
URL protocol for an entry from a zip file: "zip". |
| public static final String | WAR_URL_PREFIX
URL prefix for loading from a war file on Tomcat: "war:". |
| public static final String | WAR_URL_SEPARATOR
Special separator between WAR URL and jar part on Tomcat. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static URL | Returns: the URL for the actual jar filethe original URL jarUrl)Extract the URL for the outermost archive from the given jar/war URL (which may point to a resource in a jar file or to a jar file itself). |
| public static URL | Returns: the URL for the actual jar filethe original URL jarUrl)Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself). |
| public static File | |
| public static File | |
| public static File | |
| public static File | |
| public static File | |
| public static URL | |
| public static boolean | |
| public static boolean | Returns: whether the URL has been identified as a JAR file URLthe URL to check url)Determine whether the given URL points to a jar file itself, that is, has protocol "file" and ends with the ".jar" extension. |
| public static boolean | |
| public static boolean | |
| public static URL | Returns: the relative URL instancethe root URL to start from root, String the relative path to apply relativePath)Create a URL instance for the given root URL and relative path, going through URI construction and then URL conversion. |
| public static URI | |
| public static URI | |
| public static URL | |
| public static void | useCachesIfNecessary(URLConnection
the URLConnection to set the flag on con)Set the |
| CLASSPATH_URL_PREFIX | back to summary |
|---|---|
| public static final String CLASSPATH_URL_PREFIX Pseudo URL prefix for loading from the class path: "classpath:". | |
| FILE_URL_PREFIX | back to summary |
|---|---|
| public static final String FILE_URL_PREFIX URL prefix for loading from the file system: "file:". | |
| JAR_FILE_EXTENSION | back to summary |
|---|---|
| public static final String JAR_FILE_EXTENSION File extension for a regular jar file: ".jar". | |
| JAR_URL_PREFIX | back to summary |
|---|---|
| public static final String JAR_URL_PREFIX URL prefix for loading from a jar file: "jar:". | |
| JAR_URL_SEPARATOR | back to summary |
|---|---|
| public static final String JAR_URL_SEPARATOR Separator between JAR URL and file path within the JAR: "!/". | |
| URL_PROTOCOL_FILE | back to summary |
|---|---|
| public static final String URL_PROTOCOL_FILE URL protocol for a file in the file system: "file". | |
| URL_PROTOCOL_JAR | back to summary |
|---|---|
| public static final String URL_PROTOCOL_JAR URL protocol for an entry from a jar file: "jar". | |
| URL_PROTOCOL_VFS | back to summary |
|---|---|
| public static final String URL_PROTOCOL_VFS URL protocol for a general JBoss VFS resource: "vfs". | |
| URL_PROTOCOL_VFSFILE | back to summary |
|---|---|
| public static final String URL_PROTOCOL_VFSFILE URL protocol for a JBoss file system resource: "vfsfile". | |
| URL_PROTOCOL_VFSZIP | back to summary |
|---|---|
| public static final String URL_PROTOCOL_VFSZIP URL protocol for an entry from a JBoss jar file: "vfszip". | |
| URL_PROTOCOL_WAR | back to summary |
|---|---|
| public static final String URL_PROTOCOL_WAR URL protocol for an entry from a war file: "war". | |
| URL_PROTOCOL_WSJAR | back to summary |
|---|---|
| public static final String URL_PROTOCOL_WSJAR URL protocol for an entry from a WebSphere jar file: "wsjar". | |
| URL_PROTOCOL_ZIP | back to summary |
|---|---|
| public static final String URL_PROTOCOL_ZIP URL protocol for an entry from a zip file: "zip". | |
| WAR_URL_PREFIX | back to summary |
|---|---|
| public static final String WAR_URL_PREFIX URL prefix for loading from a war file on Tomcat: "war:". | |
| WAR_URL_SEPARATOR | back to summary |
|---|---|
| public static final String WAR_URL_SEPARATOR Special separator between WAR URL and jar part on Tomcat. | |
| ResourceUtils | back to summary |
|---|---|
| public ResourceUtils() | |
| extractArchiveURL | back to summary |
|---|---|
| public static URL extractArchiveURL(URL jarUrl) throws MalformedURLException Extract the URL for the outermost archive from the given jar/war URL (which may point to a resource in a jar file or to a jar file itself). In the case of a jar file nested within a war file, this will return a URL to the war file since that is the one resolvable in the file system.
| |
| extractJarFileURL | back to summary |
|---|---|
| public static URL extractJarFileURL(URL jarUrl) throws MalformedURLException Extract the URL for the actual jar file from the given URL (which may point to a resource in a jar file or to a jar file itself).
| |
| getFile | back to summary |
|---|---|
| public static File getFile(String resourceLocation) throws FileNotFoundException Resolve the given resource location to a Does not check whether the file actually exists; simply returns the File that the given location would correspond to.
| |
| getFile | back to summary |
|---|---|
| public static File getFile(URL resourceUrl) throws FileNotFoundException Resolve the given resource URL to a
| |
| getFile | back to summary |
|---|---|
| public static File getFile(URL resourceUrl, String description) throws FileNotFoundException Resolve the given resource URL to a
| |
| getFile | back to summary |
|---|---|
| public static File getFile(URI resourceUri) throws FileNotFoundException Resolve the given resource URI to a
| |
| getFile | back to summary |
|---|---|
| public static File getFile(URI resourceUri, String description) throws FileNotFoundException Resolve the given resource URI to a
| |
| getURL | back to summary |
|---|---|
| public static URL getURL(String resourceLocation) throws FileNotFoundException Resolve the given resource location to a Does not check whether the URL actually exists; simply returns the URL that the given location would correspond to.
| |
| isFileURL | back to summary |
|---|---|
| public static boolean isFileURL(URL url) Determine whether the given URL points to a resource in the file system, i.e. has protocol "file", "vfsfile" or "vfs".
| |
| isJarFileURL | back to summary |
|---|---|
| public static boolean isJarFileURL(URL url) Determine whether the given URL points to a jar file itself, that is, has protocol "file" and ends with the ".jar" extension.
| |
| isJarURL | back to summary |
|---|---|
| public static boolean isJarURL(URL url) Determine whether the given URL points to a resource in a jar file — for example, whether the URL has protocol "jar", "war, "zip", "vfszip", or "wsjar".
| |
| isUrl | back to summary |
|---|---|
| public static boolean isUrl(String resourceLocation) Return whether the given resource location is a URL: either a special "classpath" pseudo URL or a standard URL.
| |
| toRelativeURL | back to summary |
|---|---|
| public static URL toRelativeURL(URL root, String relativePath) throws MalformedURLException Create a URL instance for the given root URL and relative path, going through URI construction and then URL conversion.
| |
| toURI | back to summary |
|---|---|
| public static URI toURI(URL url) throws URISyntaxException Create a URI instance for the given URL, replacing spaces with "%20" URI encoding first.
| |
| toURI | back to summary |
|---|---|
| public static URI toURI(String location) throws URISyntaxException Create a URI instance for the given location String, replacing spaces with "%20" URI encoding first.
| |
| toURL | back to summary |
|---|---|
| public static URL toURL(String location) throws MalformedURLException Create a URL instance for the given location String, going through URI construction and then URL conversion.
| |
| useCachesIfNecessary | back to summary |
|---|---|
| public static void useCachesIfNecessary(URLConnection con) Set the
| |