Solved Creating a file inside a custom folder?

Discussion in 'Plugin Development' started by KarimAKL, Jun 3, 2018.

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

    KarimAKL

    What i want is to create a file inside a custom folder instead of the "getDataFolder()", how would i do that?
    What i do to create a folder:
    Code:Java
    1.  
    2. public class Main extends JavaPlugin {
    3.  
    4. public File folder = new File(getDataFolder()+File.separator+"folder");
    5.  
    6. public void onEnable() {
    7. if (!getDataFolder().exists()) {
    8. getDataFolder().mkdirs();
    9. }
    10. if (!folder.exists()) {
    11. folder.mkdirs();
    12. }
    13. }
    14. }
    15.  

    What i do to create a file:
    Code:Java
    1.  
    2. public File file = new File(getDataFolder()+"/file.txt");
    3.  
    4. //Following is inside the onEnable.
    5. if (!file.exists()) {
    6. file.createNewFile();
    7. }
    8.  

    But how would i create the file inside the folder i created?
     
    Last edited: Jun 3, 2018
  2. Offline

    Sploon

    Adjust the path:
    Code:
    public File folder = new File(path-to-file-here);
    I'm a little hung up on your confusion here, you have everything you need.
     
  3. Offline

    KarimAKL

    @Sploon Creating the folder and the files work but i want the files to be made inside the new folder instead of in the getDataFolder.
     
  4. Offline

    Sploon

    So create a new File object with the path of the file you want, and use the methods above to create the file.
     
  5. Offline

    KarimAKL

    @Sploon I was a little confused as to how i should do this, thank you for the help, this is now solved. :)
    End result:
    Code:Java
    1.  
    2. public File file = new File(getDataFolder()+"/folder/file.txt");
    3.  
     
Thread Status:
Not open for further replies.

Share This Page