Solved Deleting a text file

Discussion in 'Plugin Development' started by Ty Cleere, Apr 21, 2014.

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

    Ty Cleere

    Ok i was going over some other things ive done but they arent working for this.. this is what ive got.

    Code:java
    1. if (commandLabel.equalsIgnoreCase("wl-clear")) {
    2. if (!sender.hasPermission("uhc.wl-clear")) {
    3. sender.sendMessage(ChatColor.DARK_RED
    4. + "YOU DONT HAVE PERMISSION TO DO THIS!");
    5. return true;
    6. }
    7. for (OfflinePlayer players : Bukkit.getWhitelistedPlayers()) {
    8.  
    9. Bukkit.getWhitelistedPlayers().remove(players);
    10. }
    11.  
    12. File file = new File(getDataFolder(), "white-list.txt");
    13. if (!file.exists()) {
    14. file.mkdir();
    15. if (file.exists()) {
    16. file.delete();
    17. sender.sendMessage(ChatColor.RED
    18. + "Successfully cleared the whitelist!");
    19. }
    20. } else {
    21. sender.sendMessage(ChatColor.RED
    22. + "Whitelist has not been cleared!");
    23. }
    24. Bukkit.setWhitelist(true); // outside of the loop
    25.  
    26. }


    And i need to be able to delete the white-list.txt file in the main server folder. I want to delete it and make a new file.

    Help anyone??? lol
     
  2. Offline

    beeselmane

    Ty Cleere
    you probably shouldn't but...

    Code:
    File whitelist = new File("white-list.txt");
    if (whitelist.exists()) whitelist.delete();
    btw.. you're saying that if it doesn't exist then make it, and immediately delete it, thats probably the problem
     
  3. Offline

    Esophose

    Ty Cleere
    Well this might be a potential issue. On line 13 you have an if statement checking if the file DOESN'T exist, then inside that if statement you are checking if it DOES exist, which will never be true. Simply move the second if statement out of the first one :)
     
  4. Offline

    Ty Cleere

Thread Status:
Not open for further replies.

Share This Page