Solved I want to check if there is a yml file with this name in my folder.

Discussion in 'Spigot Plugin Development' started by Abandonggg, Mar 11, 2020.

  1. I'm new. This is the code I've tried. And I can now create a folder with a yml file Now what I want to know is If I have to specify the condition, read the yml file in that folder with the name How do I use commands?
    - Sorry if my language is incorrect Please help me


    test1.jpg test2.jpg
     
  2. drives_a_ford

    Moderator

    Please read Beginner Programming Mistakes and Why You're Making Them.
    There is no way to justify this class having static methods and fields like you've done here. Everything should be non-static and the File and FileConfiguration should be set in the constructor.

    You should also use the constructor of file that takes the parent File and the child file name as its arguments. That way you don't have to worry about the separator yourself.
    EDIT: It seems you're already doing that, but what you should be doing is getting the data folder first, making sure it exists and then getting its children.

    Lastly, you should not compare strings with ==. What this does is compare instance equivalence and two strings with the same constant can generally not be assumed to be the same instance. Use String#equals (or String#equalsIgnoreCase depending on your use case) instead.
    EDIT: This might not actually be true in what you're using (i.e not Java).
     
    #2 drives_a_ford, Mar 11, 2020
    Last edited: Mar 11, 2020
  3. For the love of god use the code block don't make screenshots

    Also there is a method you can call on the folder getFiles() (or something among those lines) wich will return an array with all the files contained in that folder from there you can check either by name or by equal..
     
  4. //Thanks for suggesting a link. I will go back to study and fix.
     

  5. //Thank you for your suggestion and apologies for using the screenshot. I just posted for the first time.