Example usage for java.io DataOutputStream close

List of usage examples for java.io DataOutputStream close

Introduction

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

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with the stream.

Usage

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();
        sock.close();//from  w  w w  . j ava 2 s .  c  om
    }
}

From source file:Main.java

public static void main(String[] arguments) {
    try {/*w w  w . j  a  va  2s  .c  o  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 {
    FileOutputStream fileOut = new FileOutputStream("data.txt");
    BufferedOutputStream buffer = new BufferedOutputStream(fileOut);
    DataOutputStream dataOut = new DataOutputStream(buffer);
    dataOut.writeUTF("Hello!");
    dataOut.writeInt(4);/*w w w  . ja v  a2  s  .c  o m*/
    dataOut.writeDouble(100.0);
    dataOut.close();
    buffer.close();
    fileOut.close();
}

From source file:WriteBinaryFile.java

public static void main(String[] args) throws Exception {
    Product[] movies = new Product[10];

    movies[0] = new Product("W", 1946, 14.95);
    movies[1] = new Product("T", 1965, 12.95);
    movies[2] = new Product("Y", 1974, 16.95);
    movies[3] = new Product("R", 1975, 11.95);
    movies[4] = new Product("S", 1977, 17.95);
    movies[5] = new Product("P", 1987, 16.95);
    movies[6] = new Product("G", 1989, 14.95);
    movies[7] = new Product("A", 1995, 19.95);
    movies[8] = new Product("Game", 1997, 14.95);
    movies[9] = new Product("F", 2001, 19.95);

    DataOutputStream out = openOutputStream("movies.dat");
    for (Product m : movies)
        writeMovie(m, out);/*  w  w w .j  a va  2 s. c  om*/
    out.close();
}

From source file:PrimeWriter.java

public static void main(String[] arguments) {
    int[] primes = new int[400];
    int numPrimes = 0;

    int candidate = 2;
    while (numPrimes < 400) {
        primes[numPrimes] = candidate;/*from   ww  w  .j  a  v  a 2 s . c  o m*/
        numPrimes++;
        candidate++;
    }

    try {
        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(primes[i]);
        data.close();
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:DataIODemo.java

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

    FileOutputStream fout = new FileOutputStream("Test.dat");
    DataOutputStream out = new DataOutputStream(fout);

    out.writeDouble(98.6);//from w  w w . j av  a2  s. c o m
    out.writeInt(1000);
    out.writeBoolean(true);

    out.close();

    FileInputStream fin = new FileInputStream("Test.dat");
    DataInputStream in = new DataInputStream(fin);

    double d = in.readDouble();
    int i = in.readInt();
    boolean b = in.readBoolean();

    System.out.println("Here are the values:  " + d + " " + i + " " + b);

    in.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 w ww.j  av a 2 s. c  o  m
    dos.writeLong(l);

    for (int i = 0; i < 10; i++)
        dos.writeInt(i);

    dos.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String sessionCookie = null;//from w  ww  . ja v a  2s.c  o 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:MainClass.java

public static void main(String[] args) throws IOException {
    DataOutputStream out2 = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Data.txt")));
    out2.writeDouble(3.14159);/*  w  w  w . j  a v  a2s.com*/
    out2.writeUTF("Square root of 2");
    out2.close();

    DataInputStream in5 = new DataInputStream(new BufferedInputStream(new FileInputStream("Data.txt")));

    System.out.println(in5.readDouble());
    System.out.println(in5.readUTF());
}

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 ww .j  a  v a  2s  .c om*/
    dos.close();

}