Java File - Open A File And Write To It

file, java

Solution

Please Search Google given to the world by Larry Page and Sergey Brin.

BufferedWriter out = null;

try {
    FileWriter fstream = new FileWriter("out.txt", true); //true tells to append data.
    out = new BufferedWriter(fstream);
    out.write("\nsue");
}

catch (IOException e) {
    System.err.println("Error: " + e.getMessage());
}

finally {
    if(out != null) {
        out.close();
    }
}

Problem

I know we are supposed to add a snipit of code to our questions, but I am seriously dumbfounded and can't wrap my head or find any examples to follow from. Basically I want to open file C:\A.txt , which already has contents in it, and write a string at the end. Basically like this. File A.txt contains: ``` John Bob Larry ``` I want to open it and write Sue at the end so the file now contains: ``` John Bob Larry Sue ``` Sorry for no code example, my brain is dead this morning....

Original source