how to create a folder inside a folder

Discussion in 'Plugin Development' started by jacklin213, Aug 19, 2012.

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

    jacklin213

    i know how u make config files but thats only inside the DataFolder
    i want to make a folder inside the data folder but i don't know how.
    this is what i have so far
    Code:
    File userfiles = new File(getDataFolder() + File.separator + "UserData.folder");
            if(!userfiles.exists()){
                userfiles.mkdirs();
                this.log.info("Missing folder!");
                this.log.info("Creating User data folder now...");
    oh and someone mind doing a try{ catch execption thingy for me thanks
     
  2. I think you got it right. Are the folders not created?

    And you don't really need a try-catch here. If it throws something like a SecurityException. Let it be thrown.
    Unless you want to do something... then do it like this:

    Code:
            File userfiles;
            try {
                userfiles = new File(getDataFolder() + File.separator + "UserData.folder");
                if(!userfiles.exists()){
                    userfiles.mkdirs();
                }
            } catch(SecurityException e) {
                // do something...
                return;
            }
    Or like this:
    Code:
            File userfiles;
            try {
                userfiles = new File(getDataFolder() + File.separator + "UserData.folder");
                if(!userfiles.exists()){
                    userfiles.mkdirs();
                }
            } catch(SecurityException e) {
                userfiles = null;
            }
         
            if(userfiles == null) {
                // do something...
            }
     
  3. Offline

    jacklin213

    for somereason the folder doesnt create..
    OMG i think i know why let me go check
     
  4. "Userdata.folder" might be considered a file, folders don't have extensions because they're not files.
    Add a File.separator at the end to force it to be considered a folder.
     
  5. Offline

    jacklin213

    if i do that do i still need the "Userdata.folder" the .folder part?
     
  6. It will create a folder named "Userdata.folder"...
     
  7. Offline

    jacklin213

    so i dont need the .folder
     
  8. No...

     
  9. Offline

    jacklin213

    k ill try it out when i get home thx
     
  10. mkdirs() will always make a directory.
    To create a file you use createNewFile() or something.
    But usually you would use FileOutputStream. Or Bukkit's YamlConfiguration class.
     
Thread Status:
Not open for further replies.

Share This Page