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:DataBase.DatabaseManager.java

public static void writeKeywordsToFile(ArrayList<Book> books) {
    LOG.info("Keywords are writting to a file...");

    try {//from   ww  w.ja  v  a2s  .  co m
        BufferedWriter out = new BufferedWriter(new FileWriter("file/keywords_output.txt", false));

        for (Book book : books) {
            for (int i = 0; i < book.getKeywords().size(); i++) {
                String line = book.getKeywords().get(i).getKeyword_id() + ";"
                        + book.getKeywords().get(i).getName();
                out.write(line);
                out.newLine();
            }

        }

        out.close();
    } catch (IOException e) {
    }
    LOG.info("Writting is done...");
}

From source file:com.tencent.wetest.common.util.ReportUtil.java

public static void updateRecord(File f, String name, String record) {

    path = WTApplication.getContext().getFilesDir().getPath();

    List<String> content = new ArrayList<String>();

    if (f.exists() && f.isFile()) {

        try {/*  w  w w  . jav  a2s . c  om*/

            String br = "";
            boolean hasRecord = false;
            BufferedReader indexreader = new BufferedReader(new FileReader(f));

            while ((br = indexreader.readLine()) != null) {
                if (br.split("/")[0].equals(name)) {

                    content.add(record);
                    hasRecord = true;
                } else {
                    content.add(br);

                }
            }

            if (!hasRecord)
                content.add(record);

            indexreader.close();

            BufferedWriter indexwriter = new BufferedWriter(new FileWriter(f, false));

            if (content.size() == 0) {

                indexwriter.write(record);

            } else {
                int i = 0;
                for (String temp : content) {

                    if (i == content.size() - 1) {
                        indexwriter.write(temp);
                    } else {
                        indexwriter.write(temp + "\t\n");
                    }
                    i++;
                }
            }

            indexwriter.flush();
            indexwriter.close();

        } catch (Exception e) {

            Logger.error("updateRecord exception : " + e.toString());
            e.printStackTrace();
        }

    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java

public static void writeNewLineToFile(File outputFile) throws IOException {
    BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile, true)), "UTF-8"));
    bw.write("\n");
    bw.flush();//from   w w  w  .ja v  a2 s .c om
    bw.close();
}

From source file:com.tactfactory.harmony.utils.TactFileUtils.java

/** convert file content to a string array with each line separated.
 * @param strings The lines to copy to the file
 * @param file The File to read/*from  w ww .  j  a  v  a2  s  .com*/
 */
public static void stringArrayToFile(final List<String> strings, final File file) {

    DataOutputStream out = null;
    BufferedWriter br = null;

    try {
        out = new DataOutputStream(new FileOutputStream(file));
        br = new BufferedWriter(new OutputStreamWriter(out, TactFileUtils.DEFAULT_ENCODING));

        for (final String string : strings) {
            br.write(string);
            br.write('\n');
        }
    } catch (final IOException e) {
        throw new RuntimeException("IO problem in fileToString", e);
    } finally {
        try {
            if (br != null) {
                br.close();
            }
            if (out != null) {
                out.close();
            }
        } catch (final IOException e) {
            ConsoleUtils.displayError(e);
        }
    }
}

From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java

/**
 * Evaluates and prints an expression to the Plugin console executed in a job.
 * // w  w w .j  a  v a  2  s .c o m
 * @param expression
 *            a R expression as a string.
 */
public static void printJob(String expression) {// helper class to print

    if (RState.isBusy() == false) {
        RState.setBusy(true);
        REvaluateJob job = new REvaluateJob(expression);
        job.addJobChangeListener(new JobChangeAdapter() {

            public void done(IJobChangeEvent event) {

                if (event.getResult().isOK()) {
                    int countDev = getDisplayNumber();
                    RState.setBusy(false);
                    if (countDev > 0) {
                        RServe.closeAndDisplay();
                    }
                    System.out.flush();
                } else {
                    RState.setBusy(false);
                    System.out.flush();
                }
            }
        });
        // job.setSystem(true);
        job.schedule();
    } else {
        Process p;
        IPreferenceStore store = Activator.getDefault().getPreferenceStore();
        if (store.getBoolean("RSERVE_NATIVE_START")) {
            ConsolePageParticipant consol = ConsolePageParticipant.getConsolePageParticipantInstance();
            p = consol.getRProcess();
        } else {
            p = RConnectionJob.getProc();
        }
        // Write to the output!
        if (p != null) {
            final OutputStream os = p.getOutputStream();
            final OutputStreamWriter osw = new OutputStreamWriter(os);
            final BufferedWriter bw = new BufferedWriter(osw, 100);
            try {
                bw.write(expression);
                bw.newLine();
                os.flush();
                bw.flush();
                // bw.close();
                System.out.flush();
            } catch (IOException e) {
                System.err.println("");
            }
        }
        MsgDialog.message("Rserve is busy!");
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java

public static void writeFeatureValuesToFile(String featureValues[], String outcome, File outputFile)
        throws IOException {
    BufferedWriter bw = new BufferedWriter(
            new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile, true)), "UTF-8"));
    bw.write("\n");
    for (String featureValue : featureValues) {
        bw.write(featureValue + " ");
    }/* w  w w. j a v a2s.c  o  m*/
    bw.write(outcome);
    bw.flush();
    bw.close();
}

From source file:com.bristle.javalib.io.FileUtil.java

/**************************************************************************
* Append the specified string to the specified file, opening and closing
* the file to do so./*from  w  ww  .j a va2s. c o m*/
*@param  strFilename   String name of the file to get.
*@param  strString     String to append to the file.
*@throws IOException   When an error occurs writing the file.
**************************************************************************/
public static void appendToFile(String strFilename, String strString) throws IOException {
    final boolean blnAPPEND = true;
    BufferedWriter fileOut = new BufferedWriter(new FileWriter(strFilename, blnAPPEND));
    fileOut.write(strString);
    fileOut.close();
}

From source file:com.ieasy.basic.util.file.FileUtils.java

/**
 * // ww w  .  ja  va2  s .  com
 * 
 * @param content
 * @param filePath
 */
public static void writeFile(String content, String filePath) {
    try {
        if (FileUtils.createFile(filePath)) {
            FileWriter fileWriter = new FileWriter(filePath, true);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            bufferedWriter.write(content);
            bufferedWriter.close();
            fileWriter.close();
        } else {
            logger.debug("??");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.uni_luebeck.inb.knowarc.usecases.invocation.local.LocalUseCaseInvocation.java

public static void persist(File directory) {
    File invocationsFile = new File(directory, LOCAL_INVOCATION_FILE);
    BufferedWriter writer = null;
    try {//from  ww w  .  j  a v a2 s.  co  m
        writer = new BufferedWriter(new FileWriter(invocationsFile));
        for (String runId : runIdToTempDir.keySet()) {
            for (String tempDir : runIdToTempDir.get(runId)) {
                writer.write(runId);
                writer.write(" ");
                writer.write(tempDir);
                writer.newLine();
            }
        }
    } catch (IOException e) {
        logger.error(e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                logger.error(e);
            }
        }
    }
}

From source file:moskitt4me.repositoryClient.core.util.RepositoryClientUtil.java

private static void addBuildProperties(IProject feature) throws Exception {

    String featureLocation = feature.getLocation().toString();
    File f = new File(featureLocation + "/build.properties");
    if (!f.exists()) {
        f.createNewFile();//w  w w .  ja v a  2  s.  c  o m
        BufferedWriter output = new BufferedWriter(new FileWriter(f));
        output.write("bin.includes = feature.xml\n");
        output.close();
    }
}