Example usage for java.io BufferedWriter newLine

List of usage examples for java.io BufferedWriter newLine

Introduction

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

Prototype

public void newLine() throws IOException 

Source Link

Document

Writes a line separator.

Usage

From source file:org.addhen.smssync.util.Util.java

/**
 * For debugging purposes. Append content of a string to a file
 * /*w  w  w  . jav a2  s.  com*/
 * @param text
 */
public static void appendLog(String text) {
    File logFile = new File(Environment.getExternalStorageDirectory(), "smssync.txt");
    if (!logFile.exists()) {
        try {
            logFile.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        // BufferedWriter for performance, true to set append to file flag
        BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
        buf.append(text);
        buf.newLine();
        buf.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java

public static <T> void collection2Text(Collection<T> c, String filename, String header) {
    BufferedWriter bw = IOUtils.getBufferedWriter(filename);
    try {/*from w w  w .  j  a  v a2  s.c o m*/
        if (header != null) {
            bw.write(header);
            bw.newLine();
        }
        for (Iterator<T> iterator = c.iterator(); iterator.hasNext();) {

            bw.write(iterator.next().toString());
            bw.newLine();
        }
        bw.flush();
        bw.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.fau.amos.FileDownload.java

/**
 * Creates a .csv file containing the data of the passed "ArrayList<ArrayList<String>> data" and saves it into the "userdir.location" directory
 * @param data/*w  w  w . j a  v a  2 s .c  om*/
 * @param fileName
 */
private static void createCsvFile(ArrayList<ArrayList<String>> data, String fileName) {

    try {
        String lines = "";

        //using Buffered Writer to write a file into the "userdir.location" directory
        BufferedWriter bw = new BufferedWriter(
                new FileWriter(new File(System.getProperty("userdir.location"), fileName)));

        //every single value will be written down into the file separated by a semicolon
        for (int i = 0; i < data.size(); i++) {
            for (int j = 0; j < data.get(i).size(); j++) {
                lines = data.get(i).get(j) + "; ";
                bw.write(lines);
            }
            bw.newLine();

        }
        bw.flush();
        bw.close();

        System.out.println("Success!");
    } catch (IOException e) {
        System.out.println("Couldn't create File!");
    }
}

From source file:cloudclient.Client.java

public static void batchReceiveResp(BufferedReader in) throws IOException, ParseException {
    BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt"));

    JSONParser parser = new JSONParser();

    String message;//from w  ww . j  a v a2s.c o  m
    while ((message = in.readLine()) != null) {
        //System.out.println(message);
        JSONArray responseList = (JSONArray) parser.parse(message);

        for (int i = 0; i < responseList.size(); i++) {
            JSONObject response = (JSONObject) responseList.get(i);
            bw.write(response.get("URL").toString());
            bw.newLine();
        }
    }

    bw.close();

}

From source file:gamlss.utilities.MatrixFunctions.java

/**
 * Write vector values to CSV file./*from   w  w  w  .j  a va2 s  . c o m*/
 * @param cmd - path to the file
 * @param v - vector to write
 */
public static void vectorWriteCSV(final String cmd, final RealVector v, boolean append) {
    try {
        // Create file 
        FileWriter fstream = new FileWriter(cmd, append);
        BufferedWriter out = new BufferedWriter(fstream);

        for (int j = 0; j < v.getDimension(); j++) {
            out.write(Double.toString(v.getEntry(j)));
            out.newLine();
        }
        out.close();
    } catch (Exception e) { //Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
}

From source file:edu.cmu.lti.oaqa.knn4qa.apps.ExtractDataAndQueryAsSparseVectors.java

private static void outputVector(BufferedWriter out, TrulySparseVector v) throws IOException {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < v.mIDs.length; ++i) {
        if (i > 0)
            sb.append(' ');
        sb.append(v.mIDs[i]);//from   w ww  . ja  v a2 s .  c om
        sb.append(':');
        sb.append(v.mVals[i]);
    }
    String res = sb.toString().trim();
    if (!res.isEmpty()) {
        out.write(res);
        out.newLine();
    }
}

From source file:nu.mine.kino.projects.utils.WriteUtils.java

public static void writePV(Project project, File file) throws ProjectException {

    BufferedWriter writer = null;
    try {//www .  j a  v a 2s  .  c om
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "MS932"));

        String header = getPVHeader(project);
        // System.out.println(header);
        writer.write(header, 0, header.length());
        writer.newLine();

        TaskInformation[] informations = project.getTaskInformations();
        for (TaskInformation taskInfo : informations) {
            String pvForPrint = getPvForPrint(project, taskInfo);
            // System.out.println(pvForPrint);

            writer.write(pvForPrint, 0, pvForPrint.length());
            writer.newLine();
        }
    } catch (FileNotFoundException e) {
        throw new ProjectException(e);
    } catch (IOException e) {
        throw new ProjectException(e);
    } finally {
        try {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
        } catch (Exception e) {
            throw new ProjectException(e);
        }
    }

}

From source file:nu.mine.kino.projects.utils.WriteUtils.java

public static void writePVForPivot(Project project, File file) throws ProjectException {

    BufferedWriter writer = null;
    try {/*from  w ww  .  j a  va 2  s  . c  om*/
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "MS932"));

        String header = getPVHeaderForPivot(project);
        // System.out.println(header);
        writer.write(header, 0, header.length());
        writer.newLine();

        TaskInformation[] informations = project.getTaskInformations();
        for (TaskInformation taskInfo : informations) {
            String pvForPivot = getPvForPivot(project, taskInfo);
            // System.out.println(pvForPrint);

            writer.write(pvForPivot, 0, pvForPivot.length());
            // writer.newLine();
        }
    } catch (FileNotFoundException e) {
        throw new ProjectException(e);
    } catch (IOException e) {
        throw new ProjectException(e);
    } finally {
        try {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
        } catch (Exception e) {
            throw new ProjectException(e);
        }
    }

}

From source file:Main.java

public static void writeInteractionInFile(Context context, String startTime, String endTime, long duration,
        String filename) throws IOException, Exception {

    BufferedWriter writer = null;
    //String path="sdcard/LifeTracker/lifetracker.csv";
    File dir = new File("sdcard/SleepLog");
    boolean flag = dir.mkdir();
    //Log.d("Directory created?",""+flag);
    File file = new File(dir.getAbsolutePath(), filename);
    if (file.exists() == false) {
        //                  Intent service = new Intent(context,DataBaseService.class);
        //                  context.startService(service);
        file.createNewFile();//from w  ww  .  ja  v  a2s. com
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.write("Start Time,End Time,Duration");
        writer.newLine();
        writer.write(startTime + "," + endTime + "," + duration);
    } else {
        writer = new BufferedWriter(new FileWriter(file, true));
        writer.newLine();
        writer.write(startTime + "," + endTime + "," + duration);
    }
    Log.d("Appended", "True");
    writer.flush();
    writer.close();

}

From source file:atg.tools.dynunit.test.util.FileUtil.java

/**
 * @see #forceGlobalScope(java.io.File)/*from w w w  .ja  v a 2  s .c  o m*/
 * @see #forceComponentScope(java.io.File, String)
 */
@Deprecated
public static void searchAndReplace(@NotNull final String originalValue, @NotNull final String newValue,
        @NotNull final File file) throws IOException {
    final File tempFile = newTempFile();

    if (CONFIG_FILES_GLOBAL_FORCE != null && CONFIG_FILES_GLOBAL_FORCE.get(file.getPath()) != null
            && CONFIG_FILES_GLOBAL_FORCE.get(file.getPath()) == file.lastModified() && file.exists()) {
        dirty = false;
        logger.debug(
                "{} last modified hasn't changed and file still exists, " + "no need for global scope force",
                file.getPath());
    } else {
        final BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
        final BufferedReader in = new BufferedReader(new FileReader(file));
        String str;
        while ((str = in.readLine()) != null) {
            if (str.contains(originalValue)) {
                out.write(newValue);
            } else {
                out.write(str);
                out.newLine();
            }
        }
        out.close();
        in.close();
        JarUtils.copy(tempFile, file, true, false);
        CONFIG_FILES_GLOBAL_FORCE.put(file.getPath(), file.lastModified());
        dirty = true;
    }

}