将传参方法改为从配置文件中读取

之前有过方法 传参时 参数是固定的, 现在因为有改动,所以做了一个properties文件来写参数,具体实现非常简单,


import java.util.HashMap;  
import java.util.Map;  
import java.util.Properties;  
  
import org.springframework.core.io.ClassPathResource;  
import org.springframework.core.io.Resource;  
import org.springframework.core.io.support.PropertiesLoaderUtils;


public class UtilFTP {
//读取.properties 结尾的配置文件用,getP, getParam  
public static Map<String,String> getP(String path) throws Exception{  
        Resource resource = new ClassPathResource(path);  
        Properties props = PropertiesLoaderUtils.loadProperties(resource);  
        Map<String,String> param = new HashMap<String,String>((Map) props);  
        return param;  
    }  

}


我们需要这样一个工具类。

实现的话调用工具类就可以了。



import java.util.Map;


public class test {


public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Map<String, String> app =UtilFTP.getP("FTP.properties");
String url=app.get("url");
int port =Integer.valueOf(app.get("port"));
String username =app.get("username");
String password =app.get("password");
String remotePath =app.get("remotePath");
String localPath =app.get("localPath");

System.out.println(url+port+username+password+remotePath+localPath);
}


我们在用的时候只需要将对应的properties 文件名字传入就可以了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值