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 Exception { FileOutputStream fos = new FileOutputStream("C:/WriteShort.txt"); DataOutputStream dos = new DataOutputStream(fos); short s = 1;/*from w w w . j ava 2 s. c om*/ dos.writeShort(s); dos.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteFloat.txt"); DataOutputStream dos = new DataOutputStream(fos); float f = 5.314f; dos.writeFloat(f);/*from w w w. jav a 2s .co m*/ dos.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteBoolean.txt"); DataOutputStream dos = new DataOutputStream(fos); boolean b = false; dos.writeBoolean(b);/*from w w w . ja va2 s . co m*/ dos.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:/WriteLong.txt"); DataOutputStream dos = new DataOutputStream(fos); long l = 65;/*www . j ava 2 s .c o m*/ dos.writeLong(l); for (int i = 0; i < 10; i++) dos.writeInt(i); dos.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(new File("temp.tmp")))); for (int i = 0; i < 10; i++) dos.writeInt(i);// w w w .ja va 2 s . co m dos.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String strFilePath = "C:/Double.txt"; FileOutputStream fos = new FileOutputStream(strFilePath); DataOutputStream dos = new DataOutputStream(fos); double d = 1; dos.writeDouble(d);/*w w w.j a v a 2 s . co m*/ dos.close(); }
From source file:MainClass.java
public static void main(String args[]) { try {//w w w .j a v a2 s .com FileOutputStream fos = new FileOutputStream(args[0]); DataOutputStream dos = new DataOutputStream(fos); dos.writeBoolean(false); dos.writeByte(Byte.MAX_VALUE); dos.writeChar('A'); dos.writeDouble(Double.MAX_VALUE); dos.writeFloat(Float.MAX_VALUE); dos.writeInt(Integer.MAX_VALUE); dos.writeLong(Long.MAX_VALUE); dos.writeShort(Short.MAX_VALUE); fos.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:Main.java
public static void main(String[] atgs) throws Exception { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java.txt"))); out.writeUTF(""); out.writeBytes("a"); out.writeChars("aaa"); out.close();//from w w w . j a v a2s. c o m DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("java.txt"))); System.out.println(in.readUTF()); byte[] buf = new byte[1024]; int len = in.read(buf); System.out.println(new String(buf, 0, len)); in.close(); }
From source file:InputOutputDemoBinaryFile.java
public static void main(String[] a) throws Exception { //Write primitive values to a binary file "java2s.dat": DataOutputStream dos = new DataOutputStream(new FileOutputStream("java2s.dat")); dos.writeInt(228);/*from w ww .ja v a 2s. c om*/ dos.writeChar(' '); dos.writeUTF("Java Source and Support at www.java2s.com"); dos.close(); //Read primitive values from binary file "java2s.dat": DataInputStream dis = new DataInputStream(new FileInputStream("java2s.dat")); System.out.println(dis.readInt() + "|" + dis.readChar() + "|" + dis.readUTF()); }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 12, 11, 22, 33, 44 }; FileOutputStream fos = new FileOutputStream("c:/test.txt"); DataOutputStream dos = new DataOutputStream(fos); int size = 0; for (byte b : buf) { dos.write(b);/*from w w w .j a v a2 s. co m*/ size = dos.size(); System.out.print("Size: " + size + "; "); } }