Example usage for java.io DataOutputStream DataOutputStream

List of usage examples for java.io DataOutputStream DataOutputStream

Introduction

In this page you can find the example usage for java.io DataOutputStream DataOutputStream.

Prototype

public DataOutputStream(OutputStream out) 

Source Link

Document

Creates a new data output stream to write data to the specified underlying output stream.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    FileOutputStream fos = new FileOutputStream(args[0]);

    DataOutputStream dos = new DataOutputStream(fos);

    dos.writeShort(1);/*from  w  w  w.j av  a2  s .  c  o  m*/

    fos.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/demo.txt");

    DataOutputStream dos = new DataOutputStream(fos);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/Int.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    int i = 100;//from  w  w  w  .  jav  a2s. co m
    dos.writeInt(i);
    dos.close();
}

From source file:Main.java

public static void main(String[] args) {
    String destFile = "primitives.dat";

    try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(destFile))) {
        dos.writeInt(765);/* ww w. ja v  a 2s  . com*/
        dos.writeDouble(6789.50);
        dos.writeBoolean(true);
        dos.writeUTF("Java Input/Output  is cool!");

        dos.flush();

        System.out.println("Data has  been  written to " + (new File(destFile)).getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/Chars.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    String str = "this is a test";
    dos.writeChars(str);/*w w w.  j  av  a  2s  . co m*/
    dos.close();
}

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);

    int i = 1;/*from  w w w .j  a  v a 2 s  .  c o m*/
    dos.writeByte(i);
    dos.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/Bytes.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    dos.writeBytes("this is a test");
    int bytesWritten = dos.size();
    System.out.println("Total " + bytesWritten + " bytes are written to stream.");
    dos.close();/* w w  w . j a  v a  2s.  c  om*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/WriteChar.txt");
    DataOutputStream dos = new DataOutputStream(fos);

    int ch = 65;/*from  w w  w  . jav a2  s  .c  o m*/
    dos.writeChar(ch);
    dos.close();
}

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();/* ww w. j  a  v a  2s .c  om*/
    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;/*from   ww  w.ja v a2s  . com*/
    dos.writeLong(l);
    dos.close();
}