1

I am trying to copy and paste a Minecraft World from a template into the server folder and then load the world. I am getting this error:

java.io.FileNotFoundException: .\C:\Users\Archie\Desktop\Server.b571c7a6-3297-48eb-ac24-1bac65ef9727\session.lock (The filename, directory name, or volume label syntax is incorrect)

So here is what I tried:

Printing out the source of the path and then the place I am copying it to, to console to check it is the correct path, here is what was printed:

C:\Users\Archie\Desktop\Server.b571c7a6-3297-48eb-ac24-1bac65ef9727 (dir to copy to)

C:\Users\Archie\Desktop\Server\plugins\Solus\gameworld (src)

That is correct. And in that folder the session.lock is literally there: http://prntscr.com/klc7xp

So I am really confused as to why it is throwing a file not found exception, I've googled it but there doesn't really seem to be a fix.

Here is the code:

private void loadWorld() {
    File game = new File(Solus.get().getServer().getWorldContainer().getAbsolutePath() + uuid.toString());
    if (!game.mkdir()) {
        System.out.println("Couldn't generate the game: " + uuid.toString());
    }

    File srcDir = new File(Solus.get().getDataFolder().getAbsolutePath() + File.separator + "gameworld");
    System.out.println(game.getPath() + "     :    " + srcDir.getAbsolutePath());
    try {
        FileUtils.copyDirectory(srcDir, game);
    } catch (IOException e) {
        e.printStackTrace();
    }

    WorldCreator wc = new WorldCreator(game.getAbsolutePath());
    wc.createWorld();
    this.world = Bukkit.getServer().createWorld(wc);
}

Code explanation:

  1. Creates the folder to store the world data inside.
  2. Creates the folder.
  3. Finds the gameworld file that needs to be copied and replicated.
  4. Copies the folder into the directory created earlier.
  5. ( Spigot ) Loads the world.
The Scientific Method
  • 2,374
  • 2
  • 14
  • 25
Archie
  • 153
  • 12
  • 4
    Nope, assertion is wrong - `.\C:` is not `C:`. The file *really doesn't* exist at that path. That should be sufficient information to fix the issue. – user2864740 Aug 21 '18 at 18:50
  • try to debug it after removing the lock and while the file is locked, check if you are getting the same exception? https://stackoverflow.com/questions/1500174/check-if-a-file-is-locked-in-java – Vishrant Aug 21 '18 at 18:52
  • Specifically `.\somefilename` is telling java to look for `somefilename` in the local directory, so don't tell it to do that. Create a `String filename = ....;` and pass that to `new File(filename)`, so you can use `System.out.println()` to see whether it's actually creating the right kind of filepath or not. Right now, it's creating a relative path instead of an absolute one. – Mike 'Pomax' Kamermans Aug 21 '18 at 18:52
  • Mike, this is what I have done, String path = game.getAbsolutePath(); System.out.println("PATH:" + path); WorldCreator wc = new WorldCreator(path); It is still doing exactly the same error, nothing has changed. Any help? – Archie Aug 21 '18 at 19:07
  • 3
    The actual directory is `Server\.b571c7a6-3297-48eb-ac24-1bac65ef9727` but you've got `Server.b571c7a6-3297-48eb-ac24-1bac65ef9727`. You're missing a separator. – Klitos Kyriacou Aug 21 '18 at 20:02
  • The exception is not produced by that piece of code that you show. There's nothing in that method that mentions session.lock. – DodgyCodeException Aug 21 '18 at 20:09
  • Klitos solved my issue, I am very sorry, I was missing a File.separater. – Archie Aug 21 '18 at 20:26
  • Btw: nice question, too. And welcome to upvote levels ;-) – GhostCat Aug 31 '18 at 09:10

0 Answers0