gpt4 book ai didi

java - 资源到url java

转载 作者:行者123 更新时间:2023-12-02 12:17:46 24 4
gpt4 key购买 nike

所以你肯定知道《我的世界》这款游戏。您可以通过 forge 添加模组。有一个我非常想要的模组,但在启动时它给了我一个错误:

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

虽然我绝对想要这个模组,而且我认为开发人员已经完成了我想要的项目,并在发现女巫功能后反编译了模组,导致我的世界崩溃,但我真的不知道出了什么问题(我不是一个大java开发人员):

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://),我会收到此错误

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

原始模组线程:http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2692177-forge-hp-spells-cast-spells-with-your-voice?page=7

PS:我是法国人,抱歉犯了错误

最佳答案

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

将其更改为

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

如果也失败了,替代解决方案可能是

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

java.io.File 中也有一个 toURL 方法,但它已被弃用,我避免使用已弃用的方法。

关于java - 资源到url java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46034099/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com