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

License:asdf

public static void main(String[] argv) throws Exception {
    File temp = File.createTempFile("pattern", ".dat");

    temp.deleteOnExit();//w w w .  ja  v  a  2s . c  o  m

    BufferedWriter out = new BufferedWriter(new FileWriter(temp));
    out.write("asdf");
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
    out.write("aString");
    out.close();/*from   ww  w  .j  a v a2s  .co  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String multilineString = "This is line 1\nthis is line 2\nthis is last line";

    FileWriter fileWriter = new FileWriter("multiline.txt", true);

    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    bufferedWriter.write(multilineString + "\n");
    bufferedWriter.flush();// ww w. j a  v a  2  s  .  c o  m
    bufferedWriter.close();
    fileWriter.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int port = 2000;
    ServerSocket srv = new ServerSocket(port);

    // Wait for connection from client.
    Socket socket = srv.accept();
    BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    wr.write("aString");
    wr.flush();//from w w w  . ja  v a 2 s  . co  m
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    StringWriter sw = new StringWriter();

    BufferedWriter bw = new BufferedWriter(sw);

    for (int i = 65; i <= 90; i++) {
        bw.write(i);
    }/*  w w  w . j av a 2s. co  m*/

    bw.flush();

    StringBuffer sb = sw.getBuffer();

    System.out.println(sb);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedWriter bufferedWriter = null;
    bufferedWriter = new BufferedWriter(new FileWriter("yourFile.txt"));
    bufferedWriter.write("string");
    bufferedWriter.newLine();/*from w w  w. j  av  a2 s.  c o  m*/
    bufferedWriter.write("string");
}

From source file:MainClass.java

public static void main(String args[]) {
    try {//from w  w  w.j a va2 s .  c o  m
        FileWriter fw = new FileWriter(args[0]);

        BufferedWriter bw = new BufferedWriter(fw);

        for (int i = 0; i < 12; i++) {
            bw.write("Line " + i + "\n");
        }

        bw.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");

    Socket socket = new Socket("127.0.0.1", 8080);

    String path = "/servlet";
    BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
    wr.write("POST " + path + " HTTP/1.0\r\n");
    wr.write("Content-Length: " + data.length() + "\r\n");
    wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
    wr.write("\r\n");

    wr.write(data);/*from w  ww. jav a2 s. c om*/
    wr.flush();

    BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }
    wr.close();
    rd.close();
}

From source file:BufferedWriterDemo.java

public static void main(String args[]) throws Exception {

    FileWriter fw = new FileWriter(args[0]);

    BufferedWriter bw = new BufferedWriter(fw);

    // Write strings to the file
    for (int i = 0; i < 12; i++) {
        bw.write("Line " + i + "\n");
    }/*w  ww  .  j  a  v  a2 s .c  o m*/

    // Close buffered writer
    bw.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream in = System.in;
    BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));

    int letter;/*from w  w w. jav  a  2 s .  com*/

    while ((letter = in.read()) != -1) {
        bw.write((char) letter);
        bw.flush();
    }
}