《精通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企业应用开发实战》读后感第六章(属性编辑器)
随机推荐
- HashMap与 HashTable, Treemap的区别
(一)HashMap 1.HashMap最多只允许一条记录的键为Null;允许多条记录的值为 Null; 2.HashMap不支持线程的同步,即任一时刻可以有多个线程同时写HashMap;可能会导致数 ...
- php部分--头像上传预览
前台页面显示 <style type="text/css"> #yl{ width:200px; height:300px; background-image:url( ...
- 消息队列activeMq 使用介绍
深入浅出 消息队列 ActiveMQhttp://blog.csdn.net/jwdstef/article/details/17380471 一. 概述与介绍 ActiveMQ 是Apache出 ...
- ridge regression 无惩罚,导致预测结果空间过大而无实用价值
[ biased regression methods to reduce variance---通过偏回归来减小方差] https://onlinecourses.science.psu.edu/s ...
- cocos2d-js添加360广告联盟插屏(通过jsb反射机制)
1.添加demo里的libs里的jar包 2.修改AndroidManifest.xml文件 添加权限: <uses-permission android:name="android. ...
- 【Leetcode-easy】Longest Common Prefix
思路:每次从字符数组中读取两个字符串比较.需要注意输入字符串为空,等细节. public String longestCommonPrefix(String[] strs) { if(strs==nu ...
- 《CSS权威指南(第三版)》---第七章 基本视觉格式化
主要知识记录: 1.给一个元素指定内容区宽度,如果设置了内边距,边框和外边距,这些因素都会影响CSS的width属性. 2.在水平格式化的7个属性中,width,margin-left,margin- ...
- 【博弈论】hihocoder
#1163 : 博弈游戏·Nim游戏 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 今天我们要认识一对新朋友,Alice与Bob. Alice与Bob总是在进行各种各样 ...
- Download rtsp.c
1. [代码][C/C++]代码 /* * Copyright (c) 2011, Jim Hollinger * All rights reserved. * * Redistribution an ...
- Mysql学习_02_mysql数据导入导出
二.参考资料 1.MySQL 数据导出