From 899230121ee373105b5d6d6bfb6569cfb99ea44c Mon Sep 17 00:00:00 2001 From: DracoYu <876319691@qq.com> Date: Thu, 20 Jun 2024 10:15:34 +0800 Subject: [PATCH] =?UTF-8?q?ResourceLoader=E8=B0=83=E6=95=B4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=A4=BA=E4=BE=8B=EF=BC=8C=E4=BB=A5=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-resources/spring-resource-resourceLoader/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-resources/spring-resource-resourceLoader/README.md b/spring-resources/spring-resource-resourceLoader/README.md index f7f0bd0d..6089f256 100644 --- a/spring-resources/spring-resource-resourceLoader/README.md +++ b/spring-resources/spring-resource-resourceLoader/README.md @@ -142,7 +142,7 @@ public class DefaultResourceLoaderDemo { Resource classpathResource = loader.getResource("classpath:application.properties"); try (InputStream is = classpathResource.getInputStream()) { // 读取和处理资源内容 - System.out.println("Classpath = "+ new String(is.readAllBytes())); + System.out.println("Classpath Exists = " + classpathResource.exists()); } catch (IOException e) { e.printStackTrace(); } @@ -151,7 +151,7 @@ public class DefaultResourceLoaderDemo { Resource fileResource = loader.getResource("file:/idea-work-space-xcs/spring-reading/spring-resources/spring-resource-resourceLoader/myfile1.txt"); try (InputStream is = fileResource.getInputStream()) { // 读取和处理资源内容 - System.out.println("File = "+ new String(is.readAllBytes())); + System.out.println("File Exists = " + fileResource.exists()); } catch (IOException e) { e.printStackTrace(); } @@ -165,7 +165,7 @@ public class DefaultResourceLoaderDemo { - 从文件系统上,我们加载了一个文件:`myfile1.txt`。这些文件位于我们之前在代码中硬编码的文件路径 `/idea-work-space-xcs/spring-reading/spring-resources/spring-resource-resourceLoader/` 下。 ```java -Classpath Exists= true +Classpath Exists = true File Exists = true ``` @@ -232,4 +232,4 @@ File Exists = true 11. **加载资源时考虑环境或属性占位符** - + 使用 `PropertyPlaceholderConfigurer` 或 `PropertySourcesPlaceholderConfigurer` 与 `@Value` 注解可以解析属性值中的资源路径。 \ No newline at end of file + + 使用 `PropertyPlaceholderConfigurer` 或 `PropertySourcesPlaceholderConfigurer` 与 `@Value` 注解可以解析属性值中的资源路径。