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 { int[] i = { 123, 234, 454, 567, 789 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (int j : i) { dos.writeInt(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) { int k = dis.readInt(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int[] i = { 123, 234, 345, 456, 678 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (int j : i) { dos.writeInt(j);/*from w ww . j a v a2 s. com*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readInt(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 12, 15, 18, 20, 22, 24 }; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (byte b : buf) { dos.writeByte(b);//ww w.j a v a 2 s . c o m } dos.flush(); for (byte b : baos.toByteArray()) { System.out.print(b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { float[] fbuf = { 12.34f, 23.34f, 45.56f, 67.78f, 12.55f, 77.88f }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (float f : fbuf) { dos.writeFloat(f);//from www . jav a 2 s. c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { float c = dis.readFloat(); System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { 12345, 12345 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/*from w w w.ja v a 2 s.co m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { short k = dis.readShort(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j);/*from w w w . j a v a 2s .c o m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.read(); System.out.print(k); dis.skipBytes(1); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { -123, 4 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j);//w w w .j a v a 2 s . co m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.readUnsignedByte(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { long[] l = { 1234567898765L, 12345678909876L }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (long j : l) { dos.writeLong(j);//from w ww . j a va 2s . 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); } }
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); for (String j : s) { dos.writeUTF(j);/* ww w .ja v a2 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 { double[] dbuf = { 12.34, 34.45, 67.78, 88.88, 66.66, 77.33 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (double d : dbuf) { dos.writeDouble(d);// w w w . ja v a2 s .c o m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { double c = dis.readDouble(); System.out.print(c); } }