Can't write to file

Discussion in 'Plugin Development' started by retsrif, Feb 15, 2011.

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

    retsrif

    Well in my player listener, I've got this code:
    Code:
    if(playerName.equals(splitA[0])) {
       String[] splitB = splitA[1].split(":");
    
       x = splitB[0];
       y = splitB[1];
       z = splitB[2];
    
       MyProperties gateFile = new MyProperties(TollGate.directory + "gates.db");
    
       gateFile.addGate(gateName, priceString, x, y, z);
    }
    It should write a gate to my file. It doesn't.
    In MyProperties, the addGate method:
    Code:
            public void addGate(String name, String cost, String x, String y, String z) {
            String gateID = (cost +"," + x + ":" + y + ":" + z);
            gates.add(name + "," + cost +"," + x + ":" + y + ":" + z);
            this.properties.setProperty(name, gateID);
            saveFile();
            }
    And this is how I load and save files in MyProperties:
    Code:
        public MyProperties(String fileName) {
            this.fileName = fileName;
            this.properties = new Properties();
            File file = new File(fileName);
    
            if(file.exists()) {
                loadFile();
            }
            else {
                saveFile();
            }
        }
    
        public void loadFile() {
            try {
            this.properties.load(new FileInputStream(this.fileName));
            }
            catch (IOException e) {
                log.log(Level.SEVERE, "Could not load " + this.fileName, e);
            }
        }
    
        public void saveFile() {
            try {
                this.properties.store(new FileOutputStream(this.fileName), "Minecraft Properties");
            }
            catch (IOException ex) {
                log.log(Level.SEVERE, "Could not save " + this.fileName, ex);
            }
        }
        
    Any help? It just doesn't write to the file for some reason!
    Also, do you have a suggestion for a better way to do this? (other than using properties)
    --- merged: Feb 16, 2011 5:41 PM ---
    anyone?
     
  2. Offline

    JoeMaximum

    Whats the content of your "TollGate.directory" ?
    Maybe its just the path that is wrong.
     
  3. Offline

    retsrif

    No I don't think so as the file gets created, but i can't write to it.
    This is the directory in my TollGate file though:
    Code:
         (new File(directory)).mkdir();
     
Thread Status:
Not open for further replies.

Share This Page