Solved yml.createNewFile(); do not work

Discussion in 'Spigot Plugin Development' started by Carster, Feb 19, 2020.

Thread Status:
Not open for further replies.
  1. Im trying to make a playerdata file but
    yml.createNewFile(); doesnt work Code:
    Code (Text):
    package events;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;

    import java.nio.file.Files;

    public class PlayerData implements Listener {
        @EventHandler(priority = EventPriority.HIGHEST)
        void onJoinEvent(PlayerJoinEvent event){
            Player player = event.getPlayer();
            File folder = new File("plugins/Carstergames", "PlayerData");
            if(!folder.exists()) {

            File yml = new File(folder, player.getPlayerListName() + ".yml");
            if(!yml.exists()) {


    #1 Carster, Feb 19, 2020
    Last edited: Feb 19, 2020
  2. Firstly, there is no need to check whether the file exists. File#createNewFile() would only create a file if it did not exist before and returns a boolean which indicates that. Secondly, are you sure that your listener works? Thirdly, is there an exception?

    You have to be a bit more clear.
Thread Status:
Not open for further replies.