Friday, September 16, 2011

JAVA FileWrite

Write text to file:

public static void FileWrite(String FileName, String Text)
{
    /*
     * (c) John Minkjan
     * 101Java.blogspot.com
     * 2011 till 2031
     */
    try {
        // Create a new file
        FileWriter fstream = new FileWriter(FileName);
        BufferedWriter out = new BufferedWriter(fstream);
        // Write the text
        out.write(Text);
        // add an extra CR;
        out.append("\r");
        //Close the output stream
        out.close();
    } catch (Exception e) { //Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
};

Till Next Time

No comments:

Post a Comment