我的游戏可以在IDE中工作,但在导出时不工作

时间:2019-04-21 21:26:49

标签: java

在我的游戏中,需要读取文件以初始化一些变量,当我在IDE中启动该文件时,它工作正常,但是在导出游戏时,游戏找不到该文件

public static void LoadBlocks() {

    ClassLoader loader = Textures.class.getClassLoader();
    URL url = loader.getResource(filePath);
    String path = url.toString().replaceFirst("file:/", "");
    System.out.println(path);

    File blockFile = new File(path + "");

    try {
        BufferedReader reader = new BufferedReader(new
                            FileReader(blockFile));
        String line;
        while((line = reader.readLine()) != null) {

            s1 = line.split("::");
                number = Double.parseDouble(s1[0]);

            s2 = s1[1].split(",");
                ID = s2[0];
                Name = s2[1];
                Traversable = Integer.parseInt(s2[2]);
                Type = s2[3];
                Placeable = Boolean.parseBoolean(s2[4]);
                Maxcount = Integer.parseInt(s2[5]);
                Time = Integer.parseInt(s2[6]);
                Path = s2[7];

                Blocks.Blocks.put(number, new Block(ID,Name,Traversable,Type,Placeable,Maxcount,Time,Path));

        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案