Solved DELETE

Discussion in 'Plugin Development' started by Nayetlam, Oct 21, 2015.

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

    Nayetlam

    I just want to create an txt file and add text to it with a command. SO i need at least 2 classes
    and i dont care if yml or not but it should not be the config.yml cuz i need it as an "log" for something.

    I dont know how and i googled but i didnt find something so i ask u guys.
    thanks ~ malte
     
  2. Offline

    teej107

  3. Offline

    guitargun

    @Nayetlam
    as with all files when reading or writing to you'll need a File instance.
    to get this file you make do (new file(pluginfolder, filename).. then check if it exists if not you create it.
    if you are writing with a .yml file make sure to have in the filename .yml instead of .txt and parse it to the YamlConfiguration.
    with writing there is a simple FileOutPutStream and FileInPutStream that writes to or reads from the file.
    for the .yml file you use it as a regular config file.

    please note for when working with a .yml file always save after you did you writing since it won't save automaticly
     
  4. Offline

    Nayetlam

    yes i tried that too but it wont create any file. and any text. (the bufferedwriter stuff)
     
  5. @Nayetlam Maybe post your code so we can help.
     
  6. Offline

    teej107

    Show code attempt and we can help you fix it. Are there any errors?
     
  7. Offline

    Nayetlam

    ok thanks dude i try my best even if i m not good with config haha

    Code:
    // I did this in main class.
    
    public static File pluginfile = new File("plugins/ETLAM/log.yml");
    
          public static void PaylogFile() {
                if (!pluginfile.exists()){
                    try {
                        pluginfile.createNewFile();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    
    
    //BUt i dont have a clue how to write to it from another class or how to add text cuz im not intelligent.
    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Oct 21, 2015
  8. Offline

    Nayetlam

    im sitting here for three hours but im too dumb cant u just tell me?. Look i have an extra class where it creates the file but i dont have a fckn clue how to make that it creates that file plus i am too dumb to get the strings from my command class into that class where i want to write something. please PLEASE i m sitting here for so long and i read so many articles in the internet but i cant find it.

    I dont want to write some letters i want a log.txt where some arguments (strings in that case) from my command executor save, can't u just tell me HOW to connect them and i dont mean the pure code and stuff
     
    Last edited: Oct 21, 2015
  9. @Nayetlam All them links tell you how to create and write to a file. I'm not going to spoonfeed.
     
  10. Offline

    Nayetlam

    yes but look i create the file, than how the daymn my plugin should open the file instantly`? Doin it in main class? Okay.

    But is there also infomation how i can operate with the file in OTHER classes? Cuz i cant just create private and public static stuff and just do it and stuff. IS the info there too? I am too dumb to find it maybe.

    EDIT: I dont want to write some letters i want a log.txt where some arguments (strings in that case) from my command executor save, can't u just tell me HOW to connect them and i dont mean the pure code and stuff
     
  11. Offline

    DoggyCode™

    @Nayetlam Jeez.. here's how you can write to a file:
    Code:
    public static void writeToLog(File file, String s) throws IOException {
            YamlConfiguration c = new YamlConfiguration();
            FileUtils.writeStringToFile(new File("plugins/" + File.separator + "myPlugin", "logs"+ ".yml"), s);
            c.save(new File("plugins/" + File.separator + "myPlugin", "logs"+ ".yml"));
        }
    You can figure out how to read it yourself
     
Thread Status:
Not open for further replies.

Share This Page