Problems with file writing.

Discussion in 'Plugin Development' started by Razorcane, Nov 26, 2011.

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

    Razorcane

    My problem is that when I run a command, the command is supposed to write to a file. However, whenever the command is run, everything in the file is removed, and then it writes the data to the file. I don't understand why this is, but if anyone could help, I would be grateful. Here is the try/catch statement for the file writing:

    Code:
    try{
                        File f = new File("plugins/Origins/groups/guests.txt");
                        FileWriter fw = new FileWriter(f);
                        f.setWritable(true);
                        fw.append(player.getName() + "\r\n");
                        plugin.guests.add(player.getName());
                        fw.close();
                        server.broadcastMessage(ChatColor.WHITE + "Added player " + ChatColor.DARK_GRAY + player.getName() + ChatColor.WHITE + " to the guest group.");
                    }
                    catch(Exception e){
                        cs.sendMessage(ChatColor.RED + "Fatal Error. Tell a dev.");
                    }
     
  2. Offline

    ItsHarry

    No idea, maybe try using a BufferedWriter instead? idk
     
  3. Offline

    xpansive

    Google for how to append to a file, thats what you want.
     
  4. Offline

    punkkeks

Thread Status:
Not open for further replies.

Share This Page