Example usage for java.io BufferedWriter write

List of usage examples for java.io BufferedWriter write

Introduction

In this page you can find the example usage for java.io BufferedWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:Main.java

public static boolean string2File(String res, File file) {
    if (file == null || res == null)
        return false;
    BufferedWriter bufferedWriter = null;
    try {//from w w w.  j av a2s .com
        bufferedWriter = new BufferedWriter(new FileWriter(file));
        bufferedWriter.write(res);
        bufferedWriter.flush();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        if (file.exists())
            file.delete();
        return false;
    } finally {
        try {
            if (bufferedWriter != null)
                bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.crfsuite.writer.CRFSuiteDataWriter.java

private static void appendEOS(BufferedWriter bf) throws Exception {
    bf.write("\t");
    bf.write("__EOS__");
    bf.write("\n");
    bf.write("\n");
}

From source file:com.oozierunner.core.FileManager.java

public static void write(BufferedWriter bufferedWriter, boolean newline, String dataline) throws IOException {

    bufferedWriter.write(dataline);

    if (newline) {

        bufferedWriter.newLine();/*from   w  w  w .  jav a2s .c  om*/
    }
}

From source file:Main.java

public static void writeFile(String path, String content, boolean append) throws FileNotFoundException {
    //File file = new File(path);
    FileOutputStream writerStream = new FileOutputStream(path, append);
    BufferedWriter writer = null;
    try {/* w ww  .j  a va  2s  .c  o  m*/
        writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8"));
        writer.write(content);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e1) {
            }
        }
    }
}

From source file:Main.java

public static void writeUserInfo(String[] info, Context c) throws IOException {
    File f = c.getFileStreamPath(userInfoPath);
    if (!f.exists()) {
        f.createNewFile();//from ww  w  .j  a  v a 2  s  .c  om
    }

    String output = "";
    for (int n = 0; n < info.length; n++) {
        output += info[n] + eol + separator + eol;
    }
    BufferedWriter out = null;
    out = new BufferedWriter(new OutputStreamWriter(c.openFileOutput(userInfoPath, Context.MODE_PRIVATE)));

    out.write(output);
    out.flush();
    out.close();
    userInfo = info;
}

From source file:Main.java

public static void writeFile(String filename, String content) {
    File file = new File(filename);

    if (!file.exists()) {
        createFile(file);/*from ww  w  .  j a v a  2 s .  c  om*/
    }

    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter(filename));
        writer.write(content);
        writer.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (writer != null) {
            try {
                writer.close();
                writer = null;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
}

From source file:com.xafero.vee.cmd.MainApp.java

private static void printVersion() throws IOException {
    StringWriter writer;//from   w w  w  .ja v  a 2s  .c o  m
    BufferedWriter out = new BufferedWriter(writer = new StringWriter());
    out.write(APP_SHORT_NAME + " " + APP_VER + " built on JSR 223.");
    out.newLine();
    out.newLine();
    out.write("Copyright (C) 2015 xafero");
    out.newLine();
    out.write("License AGPLv3+: GNU AGPL version 3 or later");
    out.newLine();
    out.write("<https://gnu.org/licenses/agpl.html>.");
    out.newLine();
    out.write("This is free software: you are free to change and redistribute it.");
    out.newLine();
    out.write("There is NO WARRANTY, to the extent permitted by law.");
    out.newLine();
    out.newLine();
    out.write("Please send bug reports and questions to <" + APP_SRC_URL + ">.");
    out.newLine();
    out.flush();
    System.out.print(writer.toString());
}

From source file:Main.java

public static void WriteAllText(String path, String text) throws IOException {
    BufferedWriter writer = null;
    try {/*from ww  w  .  j  av  a  2  s.co  m*/
        FileWriter output = new FileWriter(path);
        writer = new BufferedWriter(output);
        writer.write(text);
    } finally {
        if (writer != null)
            writer.close();
    }
}

From source file:Main.java

/**
 * Writes the current app logcat to a file.
 *
 * @param filename The filename to save it as
 * @throws IOException/*from w  w  w .  j av a 2  s .c om*/
 */
public static void writeLogcat(String filename) throws IOException {
    String[] args = { "logcat", "-v", "time", "-d" };

    Process process = Runtime.getRuntime().exec(args);
    InputStreamReader input = new InputStreamReader(process.getInputStream());
    OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(filename));
    BufferedReader br = new BufferedReader(input);
    BufferedWriter bw = new BufferedWriter(output);
    String line;

    while ((line = br.readLine()) != null) {
        bw.write(line);
        bw.newLine();
    }

    bw.close();
    output.close();
    br.close();
    input.close();
}

From source file:manager.GameElement.java

public static void save() throws IOException {
    BufferedWriter bw = new BufferedWriter(new FileWriter("scores.json"));
    bw.write(toJSON().toJSONString());
    bw.flush();//ww w.  j  a v  a  2 s .  c o m
}