List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:Main.java
public static void main(String args[]) throws Exception { String s = "<xmltag atr=value>tag data</xmltag>"; FileWriter fr = new FileWriter(new File("a.txt")); Writer br = new BufferedWriter(fr); br.write(s); br.close();//from w ww . j av a 2 s .c o m }
From source file:InputOutputDemoString.java
public static void main(String[] a) throws Exception { //Read from a String s as if it were a text file: Reader r = new StringReader("abc"); System.out.println("abc: " + (char) r.read() + (char) r.read() + (char) r.read()); //Write to a StringBuffer as if it were a text file: Writer sw = new StringWriter(); sw.write('d'); sw.write('e'); sw.write('f'); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileInputStream is = new FileInputStream("your.keystore"); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); keystore.load(is, "my-keystore-password".toCharArray()); String alias = "myalias"; Certificate cert = keystore.getCertificate(alias); File file = null;/*from ww w .jav a2 s . c o m*/ byte[] buf = cert.getEncoded(); FileOutputStream os = new FileOutputStream(file); os.write(buf); os.close(); Writer wr = new OutputStreamWriter(os, Charset.forName("UTF-8")); wr.write(new sun.misc.BASE64Encoder().encode(buf)); wr.flush(); }
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"), "UTF8")); out.write("asdf"); out.close();/*w w w .j a v a 2 s. co m*/ }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String serverName = System.getProperty("WHOIS_SERVER", DEFAULT_HOST); InetAddress server = null;//w w w . ja v a 2 s. com server = InetAddress.getByName(serverName); Socket theSocket = new Socket(server, DEFAULT_PORT); Writer out = new OutputStreamWriter(theSocket.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = theSocket.getInputStream(); InputStream in = new BufferedInputStream(theSocket.getInputStream()); int c; while ((c = in.read()) != -1) System.out.write(c); }
From source file:Main.java
License:asdf
public static void main(String[] argv) throws Exception { Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"), "8859_1")); out.write("asdf"); out.close();//w w w . j a va 2 s . c o m }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "localhost"; Socket connection = null;//from ww w . j a v a 2 s . co m connection = new Socket(hostname, DEFAULT_PORT); Writer out = new OutputStreamWriter(connection.getOutputStream(), "8859_1"); out.write("\r\n"); out.flush(); InputStream raw = connection.getInputStream(); BufferedInputStream buffer = new BufferedInputStream(raw); InputStreamReader in = new InputStreamReader(buffer, "8859_1"); int c; while ((c = in.read()) != -1) { if ((c >= 32 && c < 127) || c == '\t' || c == '\r' || c == '\n') { System.out.write(c); } } connection.close(); }
From source file:Main.java
public static void main(String[] args) { String str = "tutorial from java2s.com!"; Writer writer = new PrintWriter(System.out); try {/*from ww w . j ava2 s. c o m*/ // write a string writer.write(str); // flush the writer writer.flush(); // change line and write another string writer.write("\nThis is an example"); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char[] c1 = { 'h', 'e', 'l', 'l', 'o' }; char[] c2 = { 'w', 'o', 'r', 'l', 'd' }; Writer writer = new PrintWriter(System.out); try {//w ww . j a v a 2 s . co m // write a char array writer.write(c1); // flush the writer writer.flush(); // write a new char array writer.write(c2); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { String[] words = { "", "e", "a", "c" }; Writer w = new BufferedWriter(new OutputStreamWriter(System.out, "Cp850")); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); }//from w w w. j av a2 s . c o m Arrays.sort(words); for (int i = 0; i < 4; i++) { w.write(words[i] + " "); } w.flush(); w.close(); }