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:com.photon.phresco.util.ProjectUtils.java

/**
 * To update the project.info file with the new info
 * @param projectInfo//from w ww. jav  a2s .co m
 * @param projectInfoFile
 * @throws PhrescoException
 */
public static void updateProjectInfo(ProjectInfo projectInfo, File projectInfoFile) throws PhrescoException {
    BufferedWriter out = null;
    FileWriter fstream = null;
    try {
        Gson gson = new Gson();
        String infoJSON = gson.toJson(projectInfo);
        fstream = new FileWriter(projectInfoFile.getPath());
        out = new BufferedWriter(fstream);
        out.write(infoJSON);
    } catch (IOException e) {
        throw new PhrescoException(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
            if (fstream != null) {
                fstream.close();
            }
        } catch (IOException e) {
            throw new PhrescoException(e);
        }
    }
}

From source file:com.yunmel.syncretic.utils.io.IOUtils.java

/**
 * //w  ww  .java  2 s .  c  o m
 * 
 * @param content
 * @param filePath
 */
public static void writeFile(String content, String filePath) {
    try {
        if (IOUtils.createFile(filePath)) {
            FileWriter fileWriter = new FileWriter(filePath, true);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            bufferedWriter.write(content);
            bufferedWriter.close();
            fileWriter.close();
        } else {
            log.info("??");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:at.tugraz.sss.serv.util.SSFileU.java

public static void appendTextToFile(String filePath, String text) throws SSErr {

    FileWriter fileWriter = null;
    BufferedWriter bufferWritter = null;

    try {//from w ww  .  ja v  a2  s. co  m
        fileWriter = new FileWriter(filePath, true);
        bufferWritter = new BufferedWriter(fileWriter);

        bufferWritter.write(text);

    } catch (IOException error) {
        SSServErrReg.regErrThrow(error);
    } finally {

        if (bufferWritter != null) {
            try {
                bufferWritter.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }

        if (fileWriter != null) {
            try {
                fileWriter.close();
            } catch (IOException ex) {
                SSLogU.err(ex);
            }
        }
    }
}

From source file:com.ibm.bi.dml.runtime.util.MapReduceTool.java

public static void writeDimsFile(String filename, byte[] unknownFlags, long[] maxRows, long[] maxCols)
        throws IOException {
    BufferedWriter br = setupOutputFile(filename);
    StringBuilder line = new StringBuilder();
    for (int i = 0; i < unknownFlags.length; i++) {
        if (unknownFlags[i] != (byte) 0) {
            line.append(i);/*from w w w. ja  va  2 s  .  co  m*/
            line.append(" " + maxRows[i]);
            line.append(" " + maxCols[i]);
            line.append("\n");
        }
    }
    br.write(line.toString());
    br.close();
    //System.out.println("Finished writing dimsFile: " + filename);
}

From source file:fileoperations.FileOperations.java

public static boolean writeObjectToFile(Object ObjectToWrite, String fileToWrite) {
    loggerObj.log(Level.INFO, "inside writeObjectToFile method");
    BufferedWriter bw = null;
    loggerObj.log(Level.INFO, "File to write the object is:" + fileToWrite);
    File file = new File(fileToWrite);

    try {/*from   w  w w . ja  va 2  s . c o  m*/
        if (!file.exists()) {
            file.createNewFile();
            loggerObj.log(Level.INFO,
                    "File did not exist before: so created new one with the name: " + fileToWrite);
        }
        FileWriter fw = new FileWriter(file, true);
        bw = new BufferedWriter(fw);
        bw.write(ObjectToWrite.toString());

    } catch (IOException ex) {

        loggerObj.log(Level.SEVERE,
                "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString());
        return false;
    } catch (Exception ex) {
        loggerObj.log(Level.SEVERE,
                "Error in writing to the file:" + fileToWrite + "\n Exception is " + ex.toString());
        return false;
    } finally {
        try {
            if (bw != null) {
                bw.close();
            }
        } catch (IOException ex) {
            loggerObj.log(Level.SEVERE, "Error in closing the file:" + fileToWrite + " after reading");
            return false;
        }

    }
    loggerObj.log(Level.INFO, "Successfully written the object to: " + fileToWrite);
    return true;
}

From source file:edu.isi.pfindr.learn.util.PairsFileIO.java

public static void generatePairsFromFileWithNoClassSpecified(String inputFilePath, String pairsFileName) {

    //Buffered output file
    BufferedWriter output = null;
    try {/*from   w  ww. j a va 2s  .  c o m*/
        //Read input file into a list
        List<String> inputList = FileUtils.readLines(new File(inputFilePath));
        int fileSize = inputList.size();
        System.out.println(fileSize);
        output = new BufferedWriter(new FileWriter(pairsFileName));

        for (int i = 0; i < fileSize; i++) {
            for (int j = i + 1; j < fileSize; j++) {
                output.write(inputList.get(i).split("\t")[2] + "\t" + inputList.get(j).split("\t")[2] + "\t" + 0
                        + "\n");
            }
        }
    } catch (IOException io) {
        try {
            if (output != null)
                output.close();
            io.printStackTrace();
        } catch (IOException e) {
            System.out.println("Problem occured while closing input stream while reading file " + output);
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.websqrd.catbot.setting.CatbotSettings.java

private static boolean saveXmlRaw(String configFile, String setting) {
    logger.debug("save xml = " + configFile);
    try {/* ww w.  j a v  a  2s.co m*/
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile)));
        bw.write(setting);
        bw.close();
        return true;
    } catch (IOException e) {
        logger.error(configFile + " ? ? ??.", e);
        return false;
    }
}

From source file:jsonconverter.createandwrite.JSONFileWriter.java

public void createFile(String name, String JSONFolderPath) {
    try {//www .j a v a 2 s. c om
        File file = new File(JSONFolderPath, name + ".txt");
        file.createNewFile();
        FileWriter fw = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(obj.toString());
        bw.flush();
        bw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:it.evilsocket.dsploit.core.System.java

public static synchronized void errorLog(String tag, String data) {
    String filename = (new File(Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME))
            .getAbsolutePath();//w w w. j  a va2 s .c o  m

    data = data.trim();

    if (mContext != null && getSettings().getBoolean("PREF_DEBUG_ERROR_LOGGING", false) == true) {
        try {
            FileWriter fWriter = new FileWriter(filename, true);
            BufferedWriter bWriter = new BufferedWriter(fWriter);

            bWriter.write(data);

            bWriter.close();
        } catch (IOException ioe) {
            Log.e(TAG, ioe.toString());
        }
    }

    Log.e(tag, data);
}

From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java

private static void writeSimilarityToTextFile(double[][] similarities) {
      try {//  w w  w.ja va  2  s.com
          FileOutputStream fos = new FileOutputStream(outputFile);
          BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos));

          for (int i = 0; i < similarities.length; i++) {
              for (int j = 0; j < similarities[0].length; j++) {
                  writer.write(String.format("%f,", similarities[i][j]));
              }
              writer.newLine();
          }

          writer.close();
          fos.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }