Problems deleting file

Discussion in 'Plugin Development' started by desup, Mar 18, 2012.

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

    desup

    Hello, Ive got file Flags.tms in my plugin Directory and I need to delete it and create it again(Or make it blank) and then write new Content to it.
    Here is my snippet that I used for debugging:
    Code:
    flags.delete();
                      if(flags.exists()){
                          p.sendMessage("Fail");
                      }else{
                          flags.createNewFile();
                         
                      }
    It will alway return Fail, and I don't know why, maybe the file is used by another program?
    Can you help me solve my problem?
    Thanks.
     
  2. Offline

    Milkywayz

    Well i can link you to my configuration class.. I don't think it will solve your problem but it may. its here
     
  3. Offline

    desup

    Yes, but you are working with YAML file there, aren't you?
    But I'm working with normal text file...
     
  4. Offline

    Milkywayz

    It should matter as you can change the extension of the file ("config.yml", plugin); you can change it to .tms, if not then i suggest you take a look at either the essentials code for saving configs (items.csv) or find a new file format if possible.
     
  5. Offline

    desup

    Milkywayz
    I don't want to save configs, I want to save lines like:
    Location|Color
    for example:
    445 67 477|blue

    -Using BufferedWriter
     
  6. Offline

    Milkywayz

    Mmk i see, but if you looked that the "GoldConfiguration" theres methods to check if the file needs an update (if the file doesn't exist, if the defaults are null, or if the file is modified.
    PHP:
    public boolean needsUpdate(){
            return !
    fileExists() || !checkDefaults() || isModified();
        }
    PHP:
    public boolean fileExists(){
            try{
                return 
    file.exists();
            }catch(
    Exception ex){
                
    exception ex;
                return 
    false;
            }
        }
    PHP:
        public boolean checkDefaults(){
            if(
    getDefaults() == null){
                return 
    true;
            }
    PHP:
        public boolean isModified(){
            return 
    modified;
        }
     
  7. Offline

    desup

    I don't understand you now, my problem is that plugin is not deleting the file, and new content is appended to old.
     
  8. Offline

    Milkywayz

    Sorry i couldn't help you, sounds like you should fish around some sources until you find something useful. Again you can use Try if file exists, then if it does delete it, then create a new one. Make a delete method...
     
  9. Offline

    zwap1233

    FileWriter a = new FileWriter("file");
    it will clear your file!
    it is used whit the BufferedWriter out = new BufferedWriter(a)
    if you use FileWriter a = new FileWriter("file",true)
    it will not clear your file and it will start writing at the end of the file whit
    out.write("text");
     
Thread Status:
Not open for further replies.

Share This Page