List of usage examples for java.io StringWriter write
public void write(String str)
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) { StringWriter sw = new StringWriter(); // write a string sw.write("tutorial from java2s.com"); // print result by getting the buffer System.out.println("" + sw.getBuffer()); }
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.java2 s. c o 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); sw.write(" World"); System.out.println(sw.toString()); }
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); sw.write(76);/* w ww . ja va 2 s . co m*/ System.out.println(sw.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "yourName", "mypwd"); Statement stmt = conn.createStatement(); createBlobClobTables(stmt);/*from w w w . j a v a 2 s. c om*/ PreparedStatement pstmt = conn.prepareStatement("INSERT INTO BlobClob VALUES(40,?,?)"); File file = new File("blob.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setBinaryStream(1, fis, (int) file.length()); file = new File("clob.txt"); fis = new FileInputStream(file); pstmt.setAsciiStream(2, fis, (int) file.length()); fis.close(); pstmt.execute(); ResultSet rs = stmt.executeQuery("SELECT * FROM BlobClob WHERE id = 40"); rs.next(); java.sql.Blob blob = rs.getBlob(2); java.sql.Clob clob = rs.getClob(3); byte blobVal[] = new byte[(int) blob.length()]; InputStream blobIs = blob.getBinaryStream(); blobIs.read(blobVal); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(blobVal); blobIs.close(); char clobVal[] = new char[(int) clob.length()]; Reader r = clob.getCharacterStream(); r.read(clobVal); StringWriter sw = new StringWriter(); sw.write(clobVal); r.close(); conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "yourName", "mypwd"); Statement stmt = conn.createStatement(); createBlobClobTables(stmt);/*from www . jav a 2s . c o m*/ PreparedStatement pstmt = conn.prepareStatement("INSERT INTO BlobClob VALUES(40,?,?)"); File file = new File("blob.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setBinaryStream(1, fis, (int) file.length()); file = new File("clob.txt"); fis = new FileInputStream(file); pstmt.setAsciiStream(2, fis, (int) file.length()); fis.close(); pstmt.execute(); ResultSet rs = stmt.executeQuery("SELECT * FROM BlobClob WHERE id = 40"); rs.next(); java.sql.Blob blob = rs.getBlob(2); java.sql.Clob clob = rs.getClob("myClobColumn"); byte blobVal[] = new byte[(int) blob.length()]; InputStream blobIs = blob.getBinaryStream(); blobIs.read(blobVal); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(blobVal); blobIs.close(); char clobVal[] = new char[(int) clob.length()]; Reader r = clob.getCharacterStream(); r.read(clobVal); StringWriter sw = new StringWriter(); sw.write(clobVal); r.close(); conn.close(); }
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)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); }
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)); System.out.println("outstream: " + outStream); System.out.println("size: " + outStream.toString().length()); StringReader inStream;//ww w . ja v a 2 s .c om 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) { StringWriter sw = new StringWriter(); // create a new sequence String s = "from java2s.com"; // write a string sw.write(s); // flush the writer sw.flush();//w w w . j av a 2s .com System.out.println(sw.toString()); }