File - doesn't create any...

Discussion in 'Plugin Development' started by TGF, Oct 14, 2012.

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

    TGF

    Hi! I have a little problem.
    Part of my plugin:
    Code:
    file = new PrintWriter(this.getDataFolder()+"file.txt");
    file.println("Example");
    file.close();
    I put it in 'try' because of errors.
    But no files appear in server/plugins/pluginname folder

    I need Your help immediately!

    Refresh

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  2. Offline

    lol768

  3. Offline

    one4me

    Try this instead.
    Code:
    file = new PrintWriter(this.getDataFolder() + (File.separatorChar + "file.txt"));
    file.println("Example");
    file.close();
    
     
  4. Offline

    Vandrake

    don't forget to save it after you write in it. never worked with the file.close(); so Idk if that will do. but try to do file.save
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    You mean you never closed the pipe to your file and left the file handler occupied?!

    TGF
    also in the choice of file constructors you can use the one that takes a file and a string i.e. Also you may need to flush the stream before closing.
    Code:
    public final class SomePlugin extends JavaPlugin {
        ...
        public void onEnable() {
             ....
             FileWriter fw = new FileWriter(new File(getDataFolder(), "file.txt"));
             fw.println("Hello World");
             fw.flush();
             fw.close();
             ...
        }
        ...
    }
     
  6. Offline

    Vandrake

    Code:
    Call the file:
    File oriyml = new File(getDataFolder()+ File.separator + "players" + File.separator + convidou +  ".yml");
            FileConfiguration orifile = YamlConfiguration.loadConfiguration(oriyml);
    Save it:
    try
            {
                orifile.save(oriyml);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
    This is what I use. Is it wrong?Don't care. It works
     
  7. Offline

    Infamous Jeezy

    I think he mentions it because it could be a potential memory leak.
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    In reality it goes beyond a memory leak, You're resource (file handlers) leaking, which is even worse.
     
  9. Offline

    TGF

    ;/ It is not working.
    Only config.yml created...

    Can I use configuration functions to save data in yml like in config?
    Hope You help!
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    This post here answers your question.
     
  11. Offline

    Vandrake

    I apologize for my answer yesterday. I admit I was a little out of myself and should've stayed out of talking to people when it's like this x). Once again, I'm sorry. If you could explain me a little more about file handling, please do so. Take your time and feel free to deny my request :3 Once again xD Sorry for anyone who thinks I was rude x.x
     
Thread Status:
Not open for further replies.

Share This Page