Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

This document has been placed into the public domain by Kris


       Create a file for random access. Write some stuff to it, rewind to
       file start and read back.


private import,

void main()
        // open a file for reading
        auto fc = new File("random.bin", File.ReadWriteCreate);
        scope (exit)

        // construct (binary) reader & writer upon this conduit
        auto output = new DataOutput(fc);
        auto input = new DataInput(fc);

        int x=10, y=20;

        // write some data and flush output since IO is buffered

        // rewind to file start (0);

        // read data back again, but swap destinations
        y = input.int32;
        x = input.int32;

        assert (y==10);
        assert (x==20);