Java IO Tutorial - Java DataOutputStream .writeLong (long v)








Syntax

DataOutputStream.writeLong(long v) has the following syntax.

public final void writeLong(long v)   throws IOException

Example

In the following code shows how to use DataOutputStream.writeLong(long v) method.

/*w w w  . ja  v  a2 s .c o  m*/
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

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

    long[] l = { 1234567890L, 987654321L };
    FileOutputStream fos = new FileOutputStream("c:\\test.txt");
    DataOutputStream dos = new DataOutputStream(fos);
    for (long j : l) {
      dos.writeLong(j);
    }
    dos.flush();
    InputStream is = new FileInputStream("c:\\test.txt");

    DataInputStream dis = new DataInputStream(is);
    while (dis.available() > 0) {
      long k = dis.readLong();
      System.out.print(k);
    }
  }
}