ssh+osgi

基于SSH+OSGI框架读取文件

SSH+OSGI框架

  1. 获取tomcat服务器路径方法
//tomcat服务器发布路径
String path = request.getRealPath("/")
  1. 读取配置信息,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");
  1. 读取配置信息,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();

第一次写,也是第一次用到,不求有用,只求下次不百度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值