配置文件中读取文件存储路径

该代码段展示了如何从配置文件中读取文件存储路径,并根据不同的服务器环境(如Tomcat或WebLogic)构建相应的文件路径。它首先获取类加载器的资源路径,然后根据路径中的特定字符串(如'wtpwebapps'或'domains')来判断服务器类型,最后创建'reportFile'文件夹并在相应路径下。如果文件夹不存在,代码会创建它。
摘要由CSDN通过智能技术生成

@TOC## 配置文件中读取文件存储路径

配置文件中读取文件存储路径

private String getReportAddress() {
		String classesPath;
		try {
			classesPath = this.getClass().getClassLoader().getResource("").toURI().getPath();
		} catch (URISyntaxException e) {
			classesPath = this.getClass().getClassLoader().getResource("").getPath().replaceAll("%20"," ");
		} 
		String tempdir= "";
		//tomcat下
		if (classesPath.indexOf("wtpwebapps")!=-1) {
			tempdir = classesPath.split("wtpwebapps")[0]; 
		//weblogic下
		}else if (classesPath.indexOf("domains")!=-1) {
			tempdir = classesPath.split("domains")[0]; 
		//其他
		}else {
			tempdir = classesPath.split("webapps")[0]; 
		}
		
		if(!"/".equals(tempdir.substring(tempdir.length()-1))){  
		    tempdir += File.separator;  
		}
		String dir = tempdir+"reportFile";
		//String dir = System.getProperty("user.dir").replace("bin", "reportFile");
		//没有文件夹则创建文件夹在tomcat目录下建立reportFile文件夹
		File fileLocation = new File(dir);
		if(!fileLocation.exists()){
			fileLocation.mkdir();
		}
		return dir+File.separator;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值