java.nio.file.InvalidPathException

标签 java char

我正在制作一个我的世界服务器...并且我遇到了 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)

这是 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

这是代码:

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();
    }

这是 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];
}

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

最佳答案

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

关于java.nio.file.InvalidPathException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17266248/

相关文章:

java - Spring中如何使用@Transactional

r - 如何按字母顺序对数据框的行进行排序?

c - 警告 : multi-character character constant [-Wmultichar]|

java - 如何在java中将4字节数组转换为 float

java - 名称 [资源] 未在此上下文中绑定(bind)。找不到 [jdbc]

Java 8 由于多重继承而无法实现两个接口(interface)

java - 如何在不打破MVP模式的情况下使用Room?

java - Android 中的 HttpURLConnection 线路记录

c++ - 如何将用户输入存储为 char*?

c++ - 如何在 char 数组中分配特定数量的字节 - 内存管理