web项目中获取配置文件路径问题

现在做的是maven搭建的spring mvc项目,在service层获取code.properties图片说明

代码如下

 public static void updateProperties(String fileName,Map<String, String> keyValueMap) {  

        //String filePath = CodeTools.class.getClass().getResource("/").getPath();
         String  filePath  =  Thread.currentThread().getContextClassLoader().getResource(fileName).getPath(); 
       // String filePath = ClassLoader.getSystemClassLoader().getResource(fileName).getPath();
        Properties props = null;  
        BufferedWriter bw = null;  

        try {  
            filePath = URLDecoder.decode(filePath,"utf-8");      
            props = PropertiesLoaderUtils.loadProperties(new ClassPathResource(fileName));  

            // 写入属性文件  
            bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath)));  

            props.clear();// 清空旧的文件  

            for (String key : keyValueMap.keySet())  
                props.setProperty(key, keyValueMap.get(key));  

            props.store(bw, "");  
        } catch (IOException e) {  
        } finally {  
            try {  
                bw.close();
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
    }  

这个类在service层里,这里获取的filePath路径 转码后如下:
file:/D:/work space/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ctoc-manage/WEB-INF/lib/ctoc-service-0.0.1-SNAPSHOT.jar!/code.properties

这个路径 在这行就找不到了
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath)));

单独测试的时候是没有问题的,路径没这么复杂。在项目里就不知道 这是什么路径,求解!!!

我换了个tomcat地址,路径为:
file:/D:/apache-tomcat-7.0.68/wtpwebapps/ctoc-seller/WEB-INF/lib/ctoc-service-0.0.1-SNAPSHOT.jar!/code.properties

ctoc-service被打了包,ctoc-service-0.0.1-SNAPSHOT.jar! ,在tomcat里面怎么获取这个类的地址? 带架包的路径 输出流都不能生成。

被这些路径搞得头都晕了,help!

路径获取不对,你得文件在编译打包的时候回被打倒target下面的文件夹里面,所以你的文件的路径应该是工作空间项目目录,target目录下面的子目录里面