java.nio.file.InvalidPathException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17266248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 01:31:03  来源:igfitidea点击:

java.nio.file.InvalidPathException

javachar

提问by isxana

I am making a minecraft server...and I have a IllegalChar error Here is the log:

我正在制作一个 minecraft 服务器......我有一个 IllegalChar 错误这是日志:

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 4: file:FOO\server.properties
    at sun.nio.fs.WindowsPathParser.normalize(Unknown Source)
    at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
    at sun.nio.fs.WindowsPathParser.parse(Unknown Source)
    at sun.nio.fs.WindowsPath.parse(Unknown Source)
    at sun.nio.fs.WindowsFileSystem.getPath(Unknown Source)
    at java.io.File.toPath(Unknown Source)
    at com.sukkit.Info.loadProperties(FOO2.java:31)
    at com.sukkit.Sukit.main(FOO.java:17)

Here is the server.properties file:

这是 server.properties 文件:

generator-settings=
allow-nether=true
level-name=world
enable-query=false                       --FOURTH LINE
allow-flight=false
server-port=25565
level-type=DEFAULT
enable-rcon=false
force-gamemode=false
level-seed=
server-ip=
max-build-height=256
spawn-npcs=true
white-list=false
spawn-animals=true
hardcore=false
texture-pack=
online-mode=true
pvp=true
difficulty=1
gamemode=0
max-players=20
spawn-monsters=true
generate-structures=true
view-distance=10
motd=A Minecraft Server

And here is the code:

这是代码:

File extFile = new File("server.properties");//create external file
File inFile = new File(MAINFOO.getCodeBase(*/I HAVE CREATED THIS METHOD IN THE MAIN FOO CLASS*/)+"server.properties");//create internal file
if (!extFile.exists()){
    OutputStream out;
    try {out = new FileOutputStream(extFile);
    Files.copy(inFile.toPath(), out);
    } catch (FileNotFoundException e) {
        Sukit.logE(e.toString());
        Sukit.getLogger().severe("ERROR: FILE IS CORRUPT...PLEASE REDOWNLOAD SUKIT");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Here is the MAINFOO.getCodeBase() method:

这是 MAINFOO.getCodeBase() 方法:

public static String getCodeBase() {
    String i = ClassLoader.getSystemResource("server.properties").toString();
    String is[] = i.split("server.properties");
    logD(is[0]);
    return is[0];
}

I do not have a single : in my properties file... HELP

我的属性文件中没有一个:...帮助

回答by Martin Wickham

The problem is not the file. The problem is the file name: file:FOO\server.properties. Notice that at index 4 (character 5), you have a :. Instead, you should just use FOO\server.propertiesand omit the file:.

问题不在于文件。问题是文件名:file:FOO\server.properties. 请注意,在索引 4(字符 5)处,您有一个:. 相反,您应该只使用FOO\server.properties并省略file:.