Code example for BufferedWriter

Methods: close, write

0
        File dir1 = MyPreferences.getDataFilesDir("logs", false);
        if (dir1 == null) { return false; }
        File file = new File(dir1, FileName);
        Writer out = null;
        try { 
            out = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file.getAbsolutePath()), "UTF-8"));
            out.write(string);
            ok = true;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally { 
            try { 
                if (out != null ) {
                    out.close();
                } 
            } catch (IOException e) {}
        }         
        return ok;
    }