How to create .txt folder?

Discussion in 'Plugin Development' started by BeastCraft3, Dec 5, 2014.

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

    BeastCraft3

    Hello, I'm wondering how I create a messages.txt inside my folder. this is what I tried but didn't work, even though someone told me it would ;3
    Code:java
    1. File text = new File(plugin.getDataFolder() + File.separator + "messages.txt");


    Please help me
     
  2. Offline

    Skionz

  3. Offline

    es359

    I would take a look at this: https://docs.oracle.com/javase/tutorial/essential/io/file.html
     
  4. Offline

    Experminator

    BeastCraft3
    Code:java
    1. try {
    2. if(!(text.exists())){
    3. text.createNewFile();
    4. }
    5. } catch(Exception e){
    6. e.printStackTrace();
    7. }
    8.  
     
  5. Skionz Shameless self plug, eh? :p

    BeastCraft3 As above, you should look over the Oracle tutorials - it'd also be good to look at the Javadocs for the class in question when wondering this sort of thing :)
     
    Skionz likes this.
  6. Offline

    Skionz

  7. Offline

    BeastCraft3

    AdamQpzm Skionz Experminator es359
    Thanks for the help ! ;)
    I found it out, I'm going to post it here for the other players who need help with this:
    Code:java
    1. public void onEnable() {
    2. File dataFolder = getDataFolder();
    3. if(!dataFolder.exists())
    4. {
    5. dataFolder.mkdir();
    6. }
    7. File saveTo = new File(getDataFolder(), "messages.txt");
    8. if(!saveTo.exists())
    9. {
    10. try {
    11. saveTo.createNewFile();
    12. } catch (IOException e) {
    13. e.printStackTrace();
    14. }
    15. }
    16. }
     
  8. Offline

    Experminator

    BeastCraft3 It's a little bit unfortunately that there is no "You are the best for the community" button is!

    Because you BeastCraft3, You are a dominating helper!
     
  9. Offline

    teej107

    BeastCraft3 File#mkdirs() is better than File#mkdir() as mkdirs() makes all the directories in between that haven't been created yet.
     
  10. Offline

    xTrollxDudex

    teej107
    That's actually not going to happen :p
     
  11. Offline

    teej107

    xTrollxDudex What do you mean? In this context, yes since all the folders leading up to the top directory have been created. I've just gotten into the habit of using mkdirs().
     
Thread Status:
Not open for further replies.

Share This Page