List of usage examples for java.io DataOutputStream DataOutputStream
public DataOutputStream(OutputStream out)
From source file:Main.java
public static void main(String args[]) throws IOException { int howMany = 20; ByteArrayOutputStream bout = new ByteArrayOutputStream(howMany * 4); DataOutputStream dout = new DataOutputStream(bout); for (int i = 0; i <= 20; i++) { dout.writeInt(i);//from ww w.j a v a 2 s . c o m } FileOutputStream fout = new FileOutputStream("fibonacci.dat"); try { bout.writeTo(fout); fout.flush(); } finally { fout.close(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); while (true) { System.out.println("Listening"); Socket sock = ssock.accept(); DataOutputStream dstream = new DataOutputStream(sock.getOutputStream()); dstream.writeFloat(3.14159265f); dstream.close();/*from www. j a v a2s. com*/ sock.close(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String os = "abc"; for (byte b : os.getBytes("UTF-16BE")) { System.out.println(b);/*from w w w. j a v a 2 s . c o m*/ } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for (char c : os.toCharArray()) { dos.writeChar(c); } byte[] ba = baos.toByteArray(); for (byte b : ba) { System.out.println(b); } }
From source file:Main.java
public static void main(String[] arguments) { try {//from w w w . ja v a 2 s . co m FileOutputStream file = new FileOutputStream("p.dat"); BufferedOutputStream buff = new BufferedOutputStream(file); DataOutputStream data = new DataOutputStream(buff); for (int i = 0; i < 400; i++) data.writeInt(i); data.close(); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 }; DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat"))); fout.writeInt(data.length);//from w w w . j a v a 2 s . c o m for (double d : data) fout.writeDouble(d); DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat"))); int num = fin.readInt(); double avg = 0.0; double d; for (int i = 0; i < num; i++) { d = fin.readDouble(); avg += d; System.out.print(d + " "); } fin.close(); fout.close(); }
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);/* ww w . j a va 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.readUnsignedShort(); System.out.print(k); } }
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);//from w ww . j ava2 s . c om } 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 { short[] s = { 12345, 12345 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/*w w w .java 2 s. c o 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[] 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 . 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) { char c = dis.readChar(); System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { 123, 234 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/*from w w w. j a v a2 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); } }