《精通Spring4.X企业应用开发实战》读后感第四章(资源访问)







package com.smart.resource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.PathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.WritableResource; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; public class FileSourceExample { public static void main(String[] args) {
try {
String filePath = "E:\\learn\\spring4.x\\chapter4\\src\\main\\resources\\conf\\test.txt"; //使用系统文件路径方式加载文件
WritableResource res1 = new PathResource(filePath); //使用类路径方式加载文件
Resource res2 = new ClassPathResource("conf/test.txt"); //使用WritableResource接口写资源文件
OutputStream stream1 = res1.getOutputStream();
stream1.write("欢迎光临\n小春论坛".getBytes());
stream1.close(); //使用Resource接口读资源文件
InputStream ins1 = res1.getInputStream();
InputStream ins2 = res2.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i;
while ((i = ins1.read()) != -1) {
baos.write(i);
}
System.out.println(baos.toString()); System.out.println("res1: " + res1.getFilename());
System.out.println("res2: " + res2.getFilename()); } catch (IOException e) {
e.printStackTrace();
}
}
}












《精通Spring4.X企业应用开发实战》读后感第四章(资源访问)的更多相关文章
- 《精通Spring4.x企业应用开发实战》第三章
这一章节主要介绍SpringBoot的使用,也是学习的重点内容,之后就打算用SpringBoot来写后台,所以提前看一下还是很有必要的. 3.SpringBoot概况 3.1.1SpringBoot发 ...
- 《精通Spring4.X企业应用开发实战》读后感第七章(创建增强类)
- 《精通Spring4.X企业应用开发实战》读后感第七章(AOP基础知识、jdk动态代理,CGLib动态代理)
- 《精通Spring4.X企业应用开发实战》读后感第七章(AOP概念)
- 《精通Spring4.X企业应用开发实战》读后感第六章(容器事件)
- 《精通Spring4.X企业应用开发实战》读后感第六章(国际化)
- 《精通Spring4.X企业应用开发实战》读后感第六章(引用Bean的属性值)
- 《精通Spring4.X企业应用开发实战》读后感第六章(使用外部属性文件)
- 《精通Spring4.X企业应用开发实战》读后感第六章(属性编辑器)
随机推荐
- System.TypeLoadException: Could not load type 'System.IO.Compression.CompressionLevel' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
1.提示错误信息: zipSystem.TypeLoadException: Could not load type 'System.IO.Compression.CompressionLevel' ...
- 【BZOJ3611】[Heoi2014]大工程 欧拉序+ST表+单调栈
[BZOJ3611][Heoi2014]大工程 Description 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道. 我们这个国家位置非常特殊,可以看成是一个单位边权的树,城市位于顶 ...
- VMware虚拟机下安装RedHat Linux 9.0
从这一篇文章开始我和大家一起学习Linux系统.不管是什么样的系统,必须安装上才能谈使用对吧. Linux版本 安装Linux之前需要了解一下Linux系统的安装版本. Linux的版本分为内核版本和 ...
- 九度OJ 1046:求最大值 (基础题)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9861 解决:4013 题目描述: 输入10个数,要求输出其中的最大值. 输入: 测试数据有多组,每组10个数. 输出: 对于每组输入,请输 ...
- 使用active mq
1 windows下使用active mq 1.1 下载active mq 1.2 点击根目录\bin\win64\activemq.bat运行 1.3 登陆查看 http://localhost:8 ...
- Windows 安装nginx
http://nginx.org/en/docs/windows.html 在nginx.exe目录,打开命令行工具,用命令 启动/关闭/重启nginx start nginx : 启动ngin ...
- Java for LeetCode 102 Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- 2018年东北农业大学春季校赛 E wyh的阶乘 【数学】
题目链接 https://www.nowcoder.com/acm/contest/93/E 思路 其实就是找阶乘的项中5的个数 末尾为什么会出现0 因为存在5的倍数和偶数相乘 有0存在 借鉴 htt ...
- BZOJ 3362 Navigation Nightmare
一道带权并查集题目. 带权并查集的重点是信息的合并. 这类题出现得并不多,练习一下. #include<bits/stdc++.h> using namespace std; #defin ...
- jQuery(expression, [context])
jQuery(expression, [context]) 返回值:jQuery 概述 这个函数接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQuery 的 ...