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 Exception { Socket socket = new Socket("localhost", 12900); System.out.println("Started client socket at " + socket.getLocalSocketAddress()); BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in)); String promptMsg = "Please enter a message (Bye to quit):"; String outMsg = null;/*from w w w . j a v a 2 s . c o m*/ System.out.print(promptMsg); while ((outMsg = consoleReader.readLine()) != null) { if (outMsg.equalsIgnoreCase("bye")) { break; } // Add a new line to the message to the server, // because the server reads one line at a time. socketWriter.write(outMsg); socketWriter.write("\n"); socketWriter.flush(); // Read and display the message from the server String inMsg = socketReader.readLine(); System.out.println("Server: " + inMsg); System.out.println(); // Print a blank line System.out.print(promptMsg); } socket.close(); }
From source file:Converter.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream(new File("input.txt")); BufferedReader in = new BufferedReader(new InputStreamReader(fis, "SJIS")); FileOutputStream fos = new FileOutputStream(new File("output.txt")); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos, "UTF8")); int len = 80; char buf[] = new char[len]; int numRead;/*from w w w .j a v a 2 s .c o m*/ while ((numRead = in.read(buf, 0, len)) != -1) out.write(buf, 0, numRead); out.close(); in.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];//from w w w . jav a2 s. c om URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoInput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];//from www. jav a 2 s . c o m URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoOutput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:AllCapsDemo.java
License:asdf
public static void main(String[] arguments) { String sourceName = "asdf"; try {//from w ww. ja v a 2 s.com File source = new File(sourceName); File temp = new File("cap" + sourceName + ".tmp"); FileReader fr = new FileReader(source); BufferedReader in = new BufferedReader(fr); FileWriter fw = new FileWriter(temp); BufferedWriter out = new BufferedWriter(fw); boolean eof = false; int inChar = 0; do { inChar = in.read(); if (inChar != -1) { char outChar = Character.toUpperCase((char) inChar); out.write(outChar); } else eof = true; } while (!eof); in.close(); out.close(); boolean deleted = source.delete(); if (deleted) temp.renameTo(source); } catch (Exception se) { System.out.println("Error - " + se.toString()); } }
From source file:Main.java
public static void main(String[] args) { try {//from www.j a v a2 s. com BufferedReader input = new BufferedReader(new FileReader(args[0])); ArrayList list = new ArrayList(); String line; while ((line = input.readLine()) != null) { list.add(line); } input.close(); Collections.reverse(list); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); for (Iterator i = list.iterator(); i.hasNext();) { output.println((String) i.next()); } output.close(); } catch (IOException e) { System.err.println(e); } }
From source file:OutputStreamDemo.java
public static void main(String[] args) throws IOException { OutputStream os1 = new FileOutputStream("tmp1.dat"); writeints("Unbuffered: ", 1000000, os1); OutputStream os2 = new BufferedOutputStream(new FileOutputStream("tmp2.dat")); writeints("Buffered: ", 1000000, os2); Writer wr1 = new FileWriter("tmp1.dat"); writeints("Unbuffered: ", 1000000, wr1); Writer wr2 = new BufferedWriter(new FileWriter("tmp2.dat")); writeints("Buffered: ", 1000000, wr2); }
From source file:Main.java
public static void main(String[] args) throws Exception { String pageAddr = "http://www.google.com/index.htm"; URL url = new URL(pageAddr); String websiteAddress = url.getHost(); String file = url.getFile();/*from ww w. j ava 2 s. c o m*/ Socket clientSocket = new Socket(websiteAddress, 80); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); OutputStreamWriter outWriter = new OutputStreamWriter(clientSocket.getOutputStream()); outWriter.write("GET " + file + " HTTP/1.0\r\n\n"); outWriter.flush(); BufferedWriter out = new BufferedWriter(new FileWriter(file)); boolean more = true; String input; while (more) { input = inFromServer.readLine(); if (input == null) more = false; else { out.write(input); } } out.close(); clientSocket.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println(stdin.readLine()); BufferedReader in = new BufferedReader(new FileReader("Main.java")); String s, s2 = new String(); while ((s = in.readLine()) != null) s2 += s + "\n"; in.close();/* ww w .j a va2 s.c o m*/ StringReader in1 = new StringReader(s2); int c; while ((c = in1.read()) != -1) System.out.print((char) c); BufferedReader in2 = new BufferedReader(new StringReader(s2)); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out"))); int lineCount = 1; while ((s = in2.readLine()) != null) out1.println(lineCount++ + ": " + s); out1.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false);/*ww w . j a va 2s .c o m*/ DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new FileInputStream(new File("input.xml"))); File OutputDOM = new File("out.txt"); FileOutputStream fostream = new FileOutputStream(OutputDOM); OutputStreamWriter oswriter = new OutputStreamWriter(fostream); BufferedWriter bwriter = new BufferedWriter(oswriter); if (!OutputDOM.exists()) { OutputDOM.createNewFile(); } visitRecursively(doc, bwriter); bwriter.close(); oswriter.close(); fostream.close(); }