September 16, 2016

How To Write to a Text File in Java

Writer writer = null;
try {
    writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("filename.txt"), "UTF-8"));
    writer.write(string);
} finally {
    if (writer != null) {
        writer.close();
    }
}

No comments: