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.
Well i can link you to my configuration class.. I don't think it will solve your problem but it may. its here
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.
Milkywayz I don't want to save configs, I want to save lines like: Location|Color for example: 445 67 477|blue -Using BufferedWriter
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; }
I don't understand you now, my problem is that plugin is not deleting the file, and new content is appended to old.
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...
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");