List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:Main.java
public static void main(String[] args) throws IOException { char[] cbuf = "from java2s.com".toCharArray(); StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); bw.write(cbuf, 2, 5);/* w w w .ja v a 2 s.c om*/ bw.flush(); StringBuffer sb = sw.getBuffer(); System.out.println(sb); }
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();//from w ww .j ava 2s . c o m bufferedWriter.close(); fileWriter.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String strLine = in.readLine(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); out.write(strLine, 0, strLine.length()); out.flush();// ww w .j a v a2s . co m in.close(); out.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { String str = "from java2s.com!"; // create string writer StringWriter sw = new StringWriter(); // create buffered writer BufferedWriter bw = new BufferedWriter(sw); // writing string to writer bw.write(str, 1, 4);/*from ww w .j ava 2s.c om*/ // forces out the characters to string writer bw.flush(); // string buffer is created StringBuffer sb = sw.getBuffer(); System.out.println(sb); }
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();// w ww . j a v a 2s.c o m }
From source file:TabFilter.java
public static void main(String args[]) throws Exception { FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter(args[1]); BufferedWriter bw = new BufferedWriter(fw); // Convert tab to space characters String s;/*w w w . ja v a 2 s . c o m*/ while ((s = br.readLine()) != null) { for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '\t') c = ' '; bw.write(c); } } bw.flush(); fr.close(); fw.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.google.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedWriter writer = new BufferedWriter(new FileWriter("data.html")); String line;/*from w w w.j a v a 2s . co m*/ while ((line = reader.readLine()) != null) { System.out.println(line); writer.write(line); writer.newLine(); } reader.close(); writer.close(); }
From source file:MainClass.java
License:asdf
public static void main(String[] args) throws IOException { try {/*from w w w . j a v a2s . c o m*/ BufferedReader in4 = new BufferedReader(new StringReader("asdf")); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out"))); int lineCount = 1; String s = null; while ((s = in4.readLine()) != null) out1.println(lineCount++ + ": " + s); out1.close(); } catch (EOFException e) { System.err.println("End of stream"); } }
From source file:Main.java
License:asdf
public static void main(String[] arges) throws Exception { InetAddress addr = InetAddress.getByName(null); Socket sk = new Socket(addr, 8888); BufferedReader in = new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sk.getOutputStream())), true); out.println("asdf"); System.out.println(in.readLine()); }
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);// w w w . j a v a2 s . c o m 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(); }