Solved java.io.IOException: Unable to delete file:

Discussion in 'Plugin Development' started by Axanite, Sep 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Axanite

    Title says basically whats happening. I'm trying to delete a world folder when I run a command (/dworld <world_name>) and it seems to have deleted everything else but the region folder which is preventing the full world folder from being deleted. I see no reason as to why this is happening. Any help is greatly appreciated.
    SOURCE:
    Code:java
    1. package com.omegagamers.rf2minecraft.MultiWorld;
    2.  
    3. import org.apache.commons.io.FileUtils;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.ChatColor;
    8. import java.io.File;
    9. import java.io.IOException;
    10. import java.lang.Override;
    11.  
    12. public class DeleteWorldExecutor implements CommandExecutor {
    13. public DeleteWorldExecutor(MultiWorld multiWorld) {
    14. this.plugin = plugin;
    15. }
    16. private MultiWorld plugin;
    17.  
    18. @Override
    19. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    20. if(sender.hasPermission("multiworld.delete")) {
    21. if(cmd.getName().equalsIgnoreCase("dworld")) {
    22. if(args.length == 0) {
    23. sender.sendMessage(ChatColor.DARK_AQUA + "Please specify a world name.");
    24. sender.sendMessage(ChatColor.DARK_RED + "Correct Usage: " + "" + ChatColor.RED + "/dworld <world_name>");
    25. }
    26. if(args.length == 1) {
    27. File folder = new File(args[0]);
    28. if(folder.exists()) {
    29. sender.sendMessage(ChatColor.DARK_AQUA + "World will now be deleted.");
    30. folder.canWrite();
    31. folder.setWritable(true);
    32. try {
    33. FileUtils.forceDelete(folder);
    34. } catch (IOException e) {
    35. // TODO Auto-generated catch block
    36. e.printStackTrace();
    37. }
    38. sender.sendMessage(ChatColor.DARK_AQUA + "World " + "" + ChatColor.AQUA + args[0] + "" + ChatColor.DARK_AQUA + " has been deleted.");
    39. } else {
    40. sender.sendMessage(ChatColor.DARK_AQUA + "The world you tried to delete does not exist.");
    41. }
    42. }
    43. }
    44. }
    45. return true;
    46. }
    47. }


    I also forgot to mention, I am not in the world I am trying to delete.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    Chinwe

    I expect it is because the file is still being used - try unloading the world first using:
    Code:
    Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), true)
     
  3. Offline

    Axanite

    Ok thanks, I'll try that.

    Nope, that didn't work Chinwe. ;/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    Chinwe

    Actually, after looking around, you can't delete world folders while the server is running - unless this worked out :confused:
     
  5. Offline

    Shevchik

    You can't delete main world files while server is running, maybe that is the reason?
     
  6. Offline

    Axanite

    It seems this may not be possible without tons of advanced java which I'm not willing to try work out right now. Thanks for the help anyways guys. :)
     
Thread Status:
Not open for further replies.

Share This Page