In my game in need to read a file to Initialize some variables and it's work fine when I launch it in the IDE but when I export the game, the game can't find this file

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 Answers