url java的资源 [英] Resource to url java

查看:70
本文介绍了url java的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以您一定知道Minecraft游戏.您可以通过伪造添加mod.有一个真正想要的mod,但是启动时会给我一个错误:

So you surely know the game Minecraft. You can add mod via forge. There is a mod that a really want to have but it give me an error when lauching:

属性异常组件:'simpleNGramModel'属性:'location'-错误的URL C:\ Users \ Samuel \ Desktop \ MultiMC \ instances \ gfwg \ minecraft \ config \ spells.l已知协议:c

Property exception component:'simpleNGramModel' property:'location' - Bad URL C:\Users\Samuel\Desktop\MultiMC\instances\gfwg\minecraft\config\spells.lmunknown protocol: c

虽然我绝对想要这个mod,但我认为开发人员在发现巫婆功能后使我想要的项目无效并反编译了mod,这使我的世界飞机崩溃了,但我真的不知道出了什么问题(我不是一个大的java开发人员):

While I absolutly want this mod and I think that the dev had aboonded the project I want and decompile the mod after finding witch function make my minecraft crashes I really don't know what's going wrong (I'm not a big java developper):

edu/cmu/sphinx/util/props/ConfigurationManagerUtils.class

edu/cmu/sphinx/util/props/ConfigurationManagerUtils.class

public static URL getResource(String name, PropertySheet ps)
    throws PropertyException
  {
    String location = ps.getString(name);
    if (location == null) {
      throw new InternalConfigurationException(ps.getInstanceName(), name, "Required resource property '" + name + "' not set");
    }
    try
    {
      URL url = resourceToURL(location);
      if (url == null) {
        throw new InternalConfigurationException(ps.getInstanceName(), name, "Can't locate " + location);
      }
      return url;
    }
    catch (MalformedURLException e)
    {
      throw new InternalConfigurationException(e, ps.getInstanceName(), name, "Bad URL " + location + e.getMessage());
    }
  }

  static final Pattern jarPattern = Pattern.compile("resource:(.*)", 2);

  public static URL resourceToURL(String location)
    throws MalformedURLException
  {
    Matcher jarMatcher = jarPattern.matcher(location);
    if (jarMatcher.matches())
    {
      String resourceName = jarMatcher.group(1);
      return ConfigurationManagerUtils.class.getResource(resourceName);
    }
    if (location.indexOf(':') == -1) {
      location = "file:" + location;
    }
    return new URL(location);
  }

寻求帮助如果我将我的世界游戏移到另一个磁盘(I://),则会出现此错误

for help If I move my minecraft to an another disk (I://) I get this error

属性异常组件:'simpleNGramModel'属性:'location'-错误的网址I:\ MultiMC \ instances \ gfwg \ minecraft \ config \ spells.lmunknown协议:i

Property exception component:'simpleNGramModel' property:'location' - Bad URL I:\MultiMC\instances\gfwg\minecraft\config\spells.lmunknown protocol: i

原始mod线程: PS:对不起,我很抱歉

PS:I 'm french sorry for mistake

推荐答案

if (location.indexOf(':') == -1) {
  location = "file:" + location;
}

将其更改为

if (location.indexOf(':') != -1) {
  location = "file:///" + location.replace('\\', '/');
}

如果同样失败,则可能是另一种解决方案

If that fails as well, an alternative solution might be

if (location.indexOf(':') != -1) {
  File f = new File(location);
  return f.toURI().toURL();
}

java.io.File中也有一个toURL方法,但已弃用,我避免使用不建议使用的方法.

There is a toURL method in java.io.File as well, but it's deprecated I avoid using deprecated methods.

这篇关于url java的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆