Custom txt file,not doing what I want it to

Discussion in 'Plugin Development' started by krazyswaggaO, Jul 16, 2012.

  1. Offline

    krazyswaggaO

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Alright.basically I made the file so it writes logs that the plugin gives the console,and saves it
    Except,it only gives me one line,and when I place the block multiple time,it still gives me one line
    Any tips?
    Here's the code

    Main class:
    http://pastebin.com/Z5QG9Etr

    Listener Class:
    http://pastebin.com/3rnuTu5D

    FileWriter:
    http://pastebin.com/EuVG9yTe

    Basically,this is the results:
    #NoNoGrief Log File
    #Mon Jul 16 05:53:53 CEST 2012
    [NoNoGrief] krazyswaggaO has placed an illegal block in X:-100.47872339249258 Y:57.0 Z:83.5398635487277
    I placed the block multiple times,only got one line.
    This is the server log just if you want it:
    http://pastebin.com/TMQNQNd9
    I'm learning about files and all,so I think I missed a line or two.
  2. Offline

    Kuuichi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Instead of:

    Code:
    PrintWriter outputStream = null;
     
           try {
             
               outputStream = new PrintWriter(new FileWriter(new File("plugins/NoNoGrief/NoNoGrief.txt"), true));
               outputStream.println(warning);
               
           } finally {
     
               if (outputStream != null) {
                   outputStream.close();
               }
           }
       }
    Just make it simpler:

    Code:
    try{
        PrintWriter write = new PrintWriter(yourfile, true);
        FileWriter text = new FileWriter(write);
        text.println(blahblah);
        text.close();
        write.close();
    }catch(IOException e){
        e.printStackTrace();
    }

    This post has been edited 1 time. It was last edited by Kuuichi Jul 16, 2012.
  3. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    no, its not good to not always close the stream, his example was correct, if there is an error at your example, then the file descriptor is not closed, doing this to manny times, your unable to connect to the server annymore
  4. Offline

    krazyswaggaO

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Didn't work
    Anyone else?
  5. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    try adding some bebug statement in the saveString methode or something
  6. Offline

    krazyswaggaO

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'll try that
  7. Offline

    krazyswaggaO

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  8. Offline

    krazyswaggaO

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yea,I've tried as much as I could,no idea what to do here...

Share This Page