List of usage examples for java.io DataOutputStream flush
public void flush() throws IOException
From source file:Main.java
public static void main(String[] args) throws IOException { String s = "Hello from java2s.com!"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeBytes(s);//from www. j a v a 2 s . c o m dos.flush(); System.out.println(s + " in bytes:"); for (byte b : baos.toByteArray()) { System.out.print(b + ","); } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteByte.txt"); DataOutputStream dos = new DataOutputStream(fos); dos.writeBytes("this is a test"); dos.flush(); dos.close();/* ww w . j av a 2 s. c om*/ }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 87, 64, 72, 31, 90 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.write(buf, 2, 3);/*from www . j ava 2 s. co m*/ dos.flush(); for (byte b : baos.toByteArray()) { System.out.println(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String s = "Hello from java2s.com!!"; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); dos.writeChars(s);// w w w . j a va2 s. c o m dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { char c = dis.readChar(); System.out.print(c); } }
From source file:Main.java
public static void main(String args[]) throws Exception { String sessionCookie = null;//from ww w . java2 s.co m URL url = new java.net.URL("http://127.0.0.1/yourServlet"); URLConnection con = url.openConnection(); if (sessionCookie != null) { con.setRequestProperty("cookie", sessionCookie); } con.setUseCaches(false); con.setDoOutput(true); con.setDoInput(true); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(byteOut); out.flush(); byte buf[] = byteOut.toByteArray(); con.setRequestProperty("Content-type", "application/octet-stream"); con.setRequestProperty("Content-length", "" + buf.length); DataOutputStream dataOut = new DataOutputStream(con.getOutputStream()); dataOut.write(buf); dataOut.flush(); dataOut.close(); DataInputStream in = new DataInputStream(con.getInputStream()); int count = in.readInt(); in.close(); if (sessionCookie == null) { String cookie = con.getHeaderField("set-cookie"); if (cookie != null) { sessionCookie = parseCookie(cookie); System.out.println("Setting session ID=" + sessionCookie); } } System.out.println(count); }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { -5, 32767 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/*from w ww . java2 s .co m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readUnsignedShort(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int[] buf = { 65, 66, 67, 68, 69, 70, 71 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (int i : buf) { dos.write(i);/*from w w w. j a v a 2 s . co m*/ } dos.flush(); for (byte b : baos.toByteArray()) { char c = (char) b; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { String[] s = { "Hello", "tutorial from java2s.com!!" }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (String j : s) { dos.writeUTF(j);//ww w.j a v a 2 s . c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { String k = dis.readUTF(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 65, 66, 67, 68, 69, 70 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte b : buf) { dos.writeChar(b);//w w w . ja va2 s. co m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { char c = dis.readChar(); System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { long[] l = { 1234567890L, 987654321L }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (long j : l) { dos.writeLong(j);/* w w w . j a v a 2 s. c o m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { long k = dis.readLong(); System.out.print(k); } }