public static void writeFile(String fileName, String contents, boolean append) throws IOException {
try {
File file = new File(fileName);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(file, append), "GB2312"));
writer.write(contents);
writer.flush();
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}