List of usage examples for java.io StringWriter StringWriter
public StringWriter()
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; StringWriter sw = new StringWriter(); // write strings sw.write(s, 0, 4);//from ww w . ja v a2s . co m sw.write(s, 5, 6); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String args[]) throws IOException { StringWriter outStream = new StringWriter(); String s = "This is a test from j a va2s.com."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));//from w ww . jav a2s . c om System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); }
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. com*/ } bw.flush(); StringBuffer sb = sw.getBuffer(); System.out.println(sb); }
From source file:Main.java
public static void main(String[] args) throws IOException { StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); bw.append("java2s.com"); bw.close();/* w ww . j a va2 s. co m*/ System.out.println(sw.getBuffer()); // appending after closing will throw error bw.append("2"); System.out.println(sw.getBuffer()); }
From source file:StringIOApp.java
public static void main(String args[]) throws IOException { StringWriter outStream = new StringWriter(); String s = "This is a test."; for (int i = 0; i < s.length(); ++i) outStream.write(s.charAt(i));/* w ww.j a v a2 s . c o m*/ System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); StringReader inStream; inStream = new StringReader(outStream.toString()); int ch = 0; StringBuffer sb = new StringBuffer(""); while ((ch = inStream.read()) != -1) sb.append((char) ch); s = sb.toString(); System.out.println(s.length() + " characters were read"); System.out.println("They are: " + s); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); StringWriter sw = new StringWriter(); prop.setProperty("Chapter Count", "200"); prop.put("Tutorial Count", "1500"); prop.put("tutorial", "java2s.com"); // print the list System.out.println(prop);/*from w ww . j a va2s .c o m*/ // store the properties list in an output writer prop.store(sw, "Main"); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] args) throws IOException { String str = "from java2s.com!"; StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw, 200); }
From source file:Main.java
public static void main(String[] args) throws IOException { String str = "from java2s.com!"; StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); }
From source file:Main.java
public static void main(String args[]) { try {/*from w ww .java2 s . co m*/ throw new Exception("for no reason!"); } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); System.out.println(sw.toString().toUpperCase()); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String s = "from java2s.com!"; StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); bw.write(s, 0, 5);//w w w .java 2 s .co m bw.newLine(); bw.write(s, 6, s.length() - 6); bw.flush(); System.out.print(sw.getBuffer()); }