基于SSH+OSGI框架读取文件
SSH+OSGI框架
- 获取tomcat服务器路径方法
//tomcat服务器发布路径
String path = request.getRealPath("/")
- 读取配置信息,src下的任意目录
//src目录下的读取jdbc.properties配置文件
Properties props = new Properties();
props.load(ReportAction.class.getClassLoader().getResourceAsStream("jdbc.properties"));
String url = props.getProperty("url");
String username = props.getProperty("username");
String password = props.getProperty("password");
- 读取配置信息,src下的任意目录
方法一: 可用
BufferedInputStream in = new BufferedInputStream(ReportAction.class.getClassLoader().getResourceAsStream("a.jpg"));//src目录下
//BufferedInputStream in = new BufferedInputStream(new FileOutputStream("D://test//a.img"));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("D://test//b.img"));
byte[] by = new byte[1024];
int length = 0;
while((length = in.read(by)) != -1){
out.write(by,0,length);
}
bos.close();
方法二: 不可用
//图片无法正常显示
FileInputStream in= new FileInputStream("E:\\site.xml");
FileOutputStream in= new FileOutputStream("G:\\site-1.6.5\\site.xml");
int len = 0;
byte[] buf = new byte[1024];
if((len = in.read(buf)) != -1) {
out.write(buf, 0 , len);
}
in.close();
out.close();
第一次写,也是第一次用到,不求有用,只求下次不百度。