spring 读取操作系统上的文件
来源:互联网 发布:中国历史延续 知乎 编辑:程序博客网 时间:2024/04/30 12:36
package com.test.spring.beans;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
public class BannerLoader implements ResourceLoaderAware {
private ResourceLoader resourceLoader;
public void setResourceLoader(ResourceLoader rl) {
this.resourceLoader = rl;
}
public void showBanner() throws IOException {
Resource banner = resourceLoader.getResource("file:D:/bb.txt");
InputStream in = banner.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while (true) {
String line = reader.readLine();
if (null == line) {
break;
}
System.out.println(line);
}
reader.close();
}
public static void main(String args[]) throws IOException {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" });
BannerLoader banner = (BannerLoader) appContext.getBean("banner");
banner.showBanner();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
public class BannerLoader implements ResourceLoaderAware {
private ResourceLoader resourceLoader;
public void setResourceLoader(ResourceLoader rl) {
this.resourceLoader = rl;
}
public void showBanner() throws IOException {
Resource banner = resourceLoader.getResource("file:D:/bb.txt");
InputStream in = banner.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while (true) {
String line = reader.readLine();
if (null == line) {
break;
}
System.out.println(line);
}
reader.close();
}
public static void main(String args[]) throws IOException {
ApplicationContext appContext = new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" });
BannerLoader banner = (BannerLoader) appContext.getBean("banner");
banner.showBanner();
}
}
0 0
- spring 读取操作系统上的文件
- 读取hdfs上的文件
- Linux操作系统上的文件共享
- 读取spring配置文件的方法(spring读取资源文件)
- matlab 读取figure 文件上的数据
- 读取,下载,linux服务器上的 文件
- Java读取FTP上的txt文件
- Linux上的大文件如何读取
- 读取HDFS上的文件时报错
- 读取FastDFS文件服务器上的文件(图片)
- 读取网络上的json文件
- python 读取Linux服务器上的文件
- Spring 读取属性文件的便捷方式
- spring中属性文件properties的读取
- spring 读取属性文件的问题
- 关于spring读取文件的问题
- scala读取HDFS上的文件,每次读取一行
- spring 读取属性文件
- 属性以及点语法
- 修改协议栈内部晶振
- java怎么实现两个对象内容的交换
- 黑马程序员---IO流(一)
- Swift 入门 基础知识
- spring 读取操作系统上的文件
- iOS开发记录<1>
- Android中SwipeRefreshLayout的使用
- 程明明-关于文献阅读和寻找新的科研题目
- hdu 1269 迷宫城堡
- 临界区,互斥量,信号量,事件的区别
- java基础之对properties配置文件的读写操作
- 黑马程序员——OC-Setter/Getter函数及@proterty和@synthesize
- 黑马程序员---集合框架(一)