List of usage examples for java.io StringWriter toString
public String toString()
From source file:Main.java
public static void main(String[] args) { StringWriter sw = new StringWriter(); // write a string sw.write("tutorial from java2s.com"); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] args) { char c = 'b'; StringWriter sw = new StringWriter(); // write chars sw.write('a'); sw.write(c);//from w ww .ja v a 2 s . co m System.out.println(sw.toString()); }
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);/*www .ja v a 2s. c om*/ sw.write(" World"); System.out.println(sw.toString()); }
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);// w w w . j a v a 2 s . c o m sw.write(s, 5, 6); System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String args[]) { try {//w ww.j a v a 2s . c om 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 Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st = conn.createStatement();/*from w w w.ja v a 2s.c om*/ String query = "select * from survey where 1 = 0"; WebRowSet webRS = new WebRowSetImpl(); webRS.setCommand(query); webRS.execute(conn); // convert xml to a String object StringWriter sw = new StringWriter(); webRS.writeXml(sw); System.out.println(sw.toString()); st.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getHSQLConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("create table survey (id int,name varchar);"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')"); Statement stmt = conn.createStatement(); String sqlQuery = "SELECT * FROM survey WHERE id='1'"; WebRowSet webRS = new WebRowSetImpl(); webRS.setCommand(sqlQuery);/*from www .ja va 2s .c om*/ webRS.execute(conn); File file = new File("1.xml"); FileWriter fw = new FileWriter(file); System.out.println("Writing db data to file " + file.getAbsolutePath()); webRS.writeXml(fw); StringWriter sw = new StringWriter(); webRS.writeXml(sw); System.out.println(sw.toString()); fw.flush(); fw.close(); stmt.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) { StringWriter sw = new StringWriter(); // write integers that correspond to ascii code sw.write(70);/*w w w . ja v a2 s. co m*/ sw.write(76); System.out.println(sw.toString()); }
From source file:Main.java
static public void main(String[] arg) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(true);/*from ww w . j av a 2 s . com*/ dbf.setNamespaceAware(true); dbf.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = dbf.newDocumentBuilder(); StringReader sr = new StringReader("<tag>java2s.com</tag>"); Document document = builder.parse(new InputSource(sr)); deleteFirstElement(document); TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); StringWriter sw = new StringWriter(); trans.transform(new DOMSource(document), new StreamResult(sw)); System.out.println(sw.toString()); }
From source file:demoalchemy.DemoCloudantClient.java
/** * @param args the command line arguments *//*www . java 2 s . c om*/ public static void main(String[] args) { try { // TODO code application logic here CloudantClient client = ClientBuilder.account("2efca010-d783-48ff-8b09-a85b380b66a3-bluemix") .username("2efca010-d783-48ff-8b09-a85b380b66a3-bluemix") .password("2f040ce083e86c585ae5638a7cdba89951097a8b8a9480544d9a3d18de955533").build(); // Show the server version System.out.println("NICOOL ES LOCA - Server Version: " + client.serverVersion()); // Get a List of all the databases this Cloudant account List<String> databases = client.getAllDbs(); System.out.println("All my databases : "); for (String db : databases) { System.out.println(db); } Database db = client.database("becario", false); InputStream is = db.find("650cb18385ff988b236611625fcc3a3e"); StringWriter writer = new StringWriter(); IOUtils.copy(is, writer, "UTF-8"); String theString = writer.toString(); System.out.println(theString); } catch (IOException ex) { Logger.getLogger(DemoCloudantClient.class.getName()).log(Level.SEVERE, null, ex); } }