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:Main.java

public static void writeNode(BufferedWriter bw, String node) throws IOException {
    bw.write("\t" + node.replace("\n", "\n\t"));
    bw.newLine();
    bw.newLine();//from  w  w  w.j  av a2s. c  o m
}

From source file:Main.java

public static void writeTextFile(String[] text, String filename) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
    for (int i = 0; i < text.length; i++) {
        writer.write(text[i]);/*from   ww w.  ja v  a 2 s  .  c o m*/
        writer.newLine();
    }
    writer.close();
}

From source file:Main.java

public static void writeListToFile(String filepath, List<String> data) {
    try {//from   w ww. j a  va  2 s.  c  o  m
        File file = new File(filepath);
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fileWriter = new FileWriter(file);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        for (String line : data) {
            bufferedWriter.write(line);
            bufferedWriter.newLine();
        }

        bufferedWriter.flush();
        bufferedWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static boolean writeErrorLogToSDCard(String path, String errorLog) {
    if (!(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))) // check if SD card is mounted
        return false;

    File file;/*from w ww  . ja  v a2s  .  co m*/
    file = new File(path);
    if (!file.exists()) {
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
        } catch (IOException ioe) {
            ioe.printStackTrace();
            return false;
        }
    }

    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter(file, true)); //true means append to file
        writer.append(errorLog);
        writer.newLine();
        writer.append("-------------------------------"); // seperator
        writer.newLine();
        writer.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        return false;
    }
    return true;
}

From source file:Main.java

private static void _writeNode(BufferedWriter writer, String nodeName, String nodeValue) throws Exception {
    writer.write("<" + nodeName + ">");
    writer.write(nodeValue);// w w  w  . j  a  va2s.c om
    writer.write("</" + nodeName + ">");
    writer.newLine();
}

From source file:com.devdungeon.httpexamples.DownloadFile.java

private static void download(String url, String filepath) {
    HttpClient client = new DefaultHttpClient();

    HttpParams params = client.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 1000 * 5);
    HttpConnectionParams.setSoTimeout(params, 1000 * 5);

    HttpGet request = new HttpGet(url);

    HttpResponse response = null;/*from   www.j  a v a 2  s . c  o m*/
    try {
        response = client.execute(request);
    } catch (IOException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    }
    BufferedReader rd;
    String line = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        FileWriter fileWriter = new FileWriter(filepath);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        while ((line = rd.readLine()) != null) {
            bufferedWriter.write(line);
            bufferedWriter.newLine();
        }
        bufferedWriter.close();

    } catch (IOException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedOperationException ex) {
        Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:JMeterProcessing.JMeterPropertiesGenerator.java

private static void printProperties(BufferedWriter writer, Map<String, Long> idValuesMap) throws IOException {
    writer.newLine();

    writer.write("# Jmeter server\n");
    writer.write("full.depth.server=" + _SERVER + "\n");
    writer.write("full.depth.server.port=" + _PORT + "\n");
    writer.write("full.depth.protocol=" + _PROTOCOL + "\n");
    writer.newLine();/*w ww .  j a  va  2 s .  c o m*/

    writer.write("# Testray Object Ids\n");

    for (Map.Entry<String, Long> entry : idValuesMap.entrySet()) {
        writer.write("full.depth." + entry.getKey() + "=" + entry.getValue() + "\n");
    }

    writer.newLine();
    writer.write("# Login Info\n");
    writer.write("full.depth.user=" + _USERNAME + "\n");
    writer.write("full.depth.password=" + _PASSWORD);
}

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  ww . ja  va 2s. 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:com.oozierunner.core.FileManager.java

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

    bufferedWriter.write(dataline);/*from  w ww .  jav  a 2 s.  c  o m*/

    if (newline) {

        bufferedWriter.newLine();
    }
}

From source file:Main.java

public static void writeWarning(BufferedWriter outputFileWriter, int lineCount, String errorMessage)
        throws IOException {
    outputFileWriter.write("Warning on line " + lineCount + " : ");
    outputFileWriter.write(errorMessage);
    outputFileWriter.newLine();
}