Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceLoader调整代码示例,以匹配输出结果 #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions spring-resources/spring-resource-resourceLoader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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
```

Expand Down Expand Up @@ -232,4 +232,4 @@ File Exists = true

11. **加载资源时考虑环境或属性占位符**

+ 使用 `PropertyPlaceholderConfigurer` 或 `PropertySourcesPlaceholderConfigurer` 与 `@Value` 注解可以解析属性值中的资源路径。
+ 使用 `PropertyPlaceholderConfigurer` 或 `PropertySourcesPlaceholderConfigurer` 与 `@Value` 注解可以解析属性值中的资源路径。