Java问题从名称为#的文件夹读取文件

时间:2019-11-26 08:50:05

标签: java

我的路径类似于带有属性文件的“ D:\ Softwares \ apache-tomcat-9.0.29 \ webapps \ v2.0#portal \ WEB-INF”。文件夹名称带有#。 此文件夹包含属性文件列表。使用资源包我需要读取属性文件。

ServletContext app = getServletContext();
            String ServerUrl = getServletContext().getInitParameter("ServerURL");
            String projectTempPath = app.getRealPath("");
            String localeLang = app.getInitParameter("Language");
            URL resourceURL = null;
            String localeCountry = app.getInitParameter("Country");         
            String path = request.getRealPath("WEB-INF/" + localeLang + "_" + localeCountry + ".properties");
            Locale locale = new Locale(localeLang, localeCountry);
            java.io.File filePath = new java.io.File(path); 
            logger.info("File "+filePath);                      
            try {
                resourceURL = filePath.getParentFile().toURL();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }

            URLClassLoader urlLoader = new URLClassLoader(new java.net.URL[]{resourceURL});

            java.util.ResourceBundle bundle=null;
            try{
            bundle = java.util.ResourceBundle.getBundle(localeLang + "_" + localeCountry,
                    locale, urlLoader);
            }
            catch (Exception e) {
                logger.info("ERROR "+ e.getMessage());
            }

我收到错误消息“找不到基本名称为en_US,语言环境为en_US的捆绑软件”。 没有路径名称为#的文件夹没有问题

0 个答案:

没有答案