Java tutorial
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; public class Main { private static void saveStr(String path, String xml, boolean isAppend) { OutputStream out = null; OutputStreamWriter outwriter = null; try { File file = new File(path); if (!file.exists()) { file.createNewFile(); } out = new FileOutputStream(path, isAppend); outwriter = new OutputStreamWriter(out, "UTF-8"); outwriter.write(xml); outwriter.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (outwriter != null) { outwriter.close(); } if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } } }