How do I create a directory in the user's file system?

Discussion in 'Plugin Development' started by Spex_guy, Nov 25, 2011.

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

    Spex_guy

    I am making a plugin that uses multiple files, and I want to be able to save all of them in one folder located at <wherever the server is>\myModName\aFile.dat . How can I make my code create this directory automatically if it doesn't already exist? Thanks in advance for the help!
     
  2. Offline

    Pazflor

    Place this in your onEnable():

    Code:java
    1. File folder = this.getDataFolder();
    2. File file = new File(folder + File.separator
    3. + "file.dat");
    4.  
    5. if (!folder.exists() && (!file.exists())) {
    6. try {
    7. folder.mkdir();
    8. file.createNewFile();
    9. } catch (Exception e) {
    10. e.printStackTrace();
    11. }
    12. }
     
Thread Status:
Not open for further replies.

Share This Page