获取资源文件 @param resourceLocation @return @throws FileNotFoundException
(String resourceLocation)
| 475 | * @throws FileNotFoundException |
| 476 | */ |
| 477 | public static File getFile(String resourceLocation) throws FileNotFoundException { |
| 478 | AssertUtil.notNull(resourceLocation,"Resource location must not be null"); |
| 479 | if (resourceLocation.startsWith("classpath:")) { |
| 480 | String path = resourceLocation.substring("classpath:".length()); |
| 481 | String description = "class path resource [" + path + "]"; |
| 482 | ClassLoader cl = getContextClassLoader(); |
| 483 | URL url = cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path); |
| 484 | if (url == null) { |
| 485 | throw new FileNotFoundException(description + " cannot be resolved to absolute file path because it does not exist"); |
| 486 | } else { |
| 487 | return getFile(url, description); |
| 488 | } |
| 489 | } else { |
| 490 | try { |
| 491 | return getFile(new URL(resourceLocation)); |
| 492 | } catch (MalformedURLException var5) { |
| 493 | return new File(resourceLocation); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | public static File getFile(URL resourceUrl) throws FileNotFoundException { |
| 499 | return getFile(resourceUrl, "URL"); |
no test coverage detected