C:\Documents%20and%20Settings\Administrator..(系统找不到指定的路径。)

来源:互联网 发布:没有淘宝能有支付宝吗 编辑:程序博客网 时间:2024/06/05 07:47
代码: public static String getLocalIp() {
        if (localIp == null) {
            try {
                Properties props = new Properties();
                String path = SystemService.class.getResource("/config/cbp.properties").getFile();
                InputStream in = new BufferedInputStream(new FileInputStream(path));
                props.load(in);
                localIp = props.getProperty("local.ip");
            } catch (Exception e) {
                ExceptionHolder exceptionHolder = new ExceptionHolder(e);
                logger.error(exceptionHolder.getExceptionStack());
            }
        }
        return localIp;

    }

修改为:

 public static String getLocalIp() {
        if (localIp == null) {
            try {
                Properties props = new Properties();
                String path = SystemService.class.getResource("/config/cbp.properties").getFile();
                try {
                    path = java.net.URLDecoder.decode(path, "UTF-8");
                } catch (Exception e) {
                    e.printStackTrace();
                }

                InputStream in = new BufferedInputStream(new FileInputStream(path));
                props.load(in);
                localIp = props.getProperty("local.ip");
            } catch (Exception e) {
                ExceptionHolder exceptionHolder = new ExceptionHolder(e);
                logger.error(exceptionHolder.getExceptionStack());
            }
        }
        return localIp;
    }