Problem creating a properties file
<p>This is what I finally ended up doing. It works great but could probably use some fine tuning. </p>

<pre><code>File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");
FileInputStream inStream = null;
FileOutputStream outStream = null;
Properties config = new Properties();

        try{
            if (file.exists()){//Checks if it exists.
            inStream = new FileInputStream(file);
                if (inStream.available() &gt;= 0){//Cheacks if it has anything in it.
                    config.load(inStream);
                    System.out.println(config);
                }
            }

            config.setProperty(property , score);//New property
            outStream = new FileOutputStream(file);
            config.store(outStream, "Property");//Names the Properties that are in the file Property
            config.list(System.out);//Prints out all the properties. 

        } catch (IOException ioe){//Handles any problems
            System.out.println("You just pooped the pants");
        } finally{//Closes both input and output Streams if they are open
            try {
                if(inStream != null)
                    inStream.close();
                if (outStream != null)
                    outStream.close();
            } catch (IOException e) {
            }
        }
}
</code></pre>

<p>I have two sets of code. One that just writes a property to a file and one that is a bit more in depth. I think they should both be writing the fill if it doesn't exist but only one of them does. Here is each code with some extras. I'm just using the console right now and I'm just messing around so its not flashy at all. </p>

<pre><code>private void properties() {
    System.out.println("What would you like to name the .properties file?");
    sTest.stringReader();
    String fileName =sTest.getString();// This will be the name of the file. 
    System.out.println("What property would you like to change?");
    sTest.stringReader();   
    String property= sTest.getString();
    System.out.println("What would you like to change the " + property + " to?");
    sTest.stringReader();
    String score = sTest.getString();

        try {
            File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");
            FileInputStream inStream = new FileInputStream(file);
            Properties config = new Properties();
            config.load(inStream);
            // Create a new property
            config.setProperty(property , score);
            FileOutputStream outStream = new FileOutputStream(file);
            config.store(outStream, "Property");
            inStream.close();
            outStream.close();
            config.list(System.out);
        } catch (IOException ioe){
            System.out.println("Chould not write file.");
        }
}
</code></pre>

<p>And here is the one that just writes a property without adding any thing to it. This method is the one that creates the file but I feel that "File file = new File" should do it for both. But then again feelings don't account for much when programming. I'd love an explanation. Thanks. </p>

<pre><code>private void myWrite() {
    System.out.println("What would you like to name your file?");
    sTest.stringReader();
    String fileName =sTest.getString();// This will be the name of the file. 
    System.out.println("What would you like to put in you file?");
    sTest.stringReader();
    String letsWrite = sTest.getString();
        try {
            File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");
            FileOutputStream fileStream = new FileOutputStream(file);
            write(fileStream, letsWrite);
        } catch (IOException ioe){
            System.out.println("Could not write file" + ioe);
        }
    }
</code></pre>

<p>Redo on the code with your help:</p>

<pre><code>System.out.println("What would you like to change the " + property + " to?");
    sTest.stringReader();
    String score = sTest.getString();

    try {
        File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");
        FileInputStream inStream = new FileInputStream(file);
        Properties config = new Properties();
        config.load(inStream);
        inStream.close();
    } catch (IOException ioe){
        System.out.println("Chould not read file.");
    }

    try{
        File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");
        FileOutputStream outStream = new FileOutputStream(file);
        Properties config = new Properties();
        config.setProperty(property , score);
        config.store(outStream, "Property");
        outStream.close();
    } catch (IOException ioe){
        System.out.println("Chould not write file.");
    }
</code></pre>

<p>It throws the IOException but it does write the file. How would I close it in a finally block? I haven't used those yet. How do you just load the file first? I'm still working on it I just wanted to get this to you while you were still on. Thanks for your help.</p>

<p>I'm still not getting this very well. I have put in notes of what I think everything is doing. I'll be asking my friend later tonight what is going on but he is more of a MatLab guy. </p>

<pre><code>File file = new File("C:/Users/Mike Home/Desktop/"+fileName+".properties");//new instance of these file
    FileInputStream inStream = null; //Creates variable out side my try block
    FileOutputStream outStream = null;//Creates variable out side my try block
    Properties config = new Properties();//Creates variable out side my try block
    try {
        inStream = new FileInputStream(file); //Loads the file to the Input Stream
        config.load(inStream); //Loads the config with what was in the inStream.

    } catch (IOException ioe){//Handles any problems
        System.out.println("Chould not read file.");
    }

    try{
        //inStream = new FileInputStream(file);//Do I need to do this again? 
        //config.load(inStream);// Do I need to do this again? 

        //Creates a new property
        config.setProperty(property , score);

        outStream = new FileOutputStream(file); // Preps the outPut stream to write to the file
        config.store(outStream, "Property");//Names the Properties that are in the file Property
        config.list(System.out);//Prints out all the properties. 
    } catch (IOException ioe){//Handles any problems
        System.out.println("Chould not write file.");
    } finally{//Closes both input and output Streams
        try {
            inStream.close();//It says these need to be in a try/catch block also. 
        } catch (IOException e) {
        }
        try {
            outStream.close();
        } catch (IOException e) {
        }
    }
</code></pre>
