Create DataOutputStream out of BufferedOutputStream : BufferedOutputStream « File « Java Tutorial






import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

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

    int candidate = 2;
    while (numPrimes < 400) {
      primes[numPrimes] = candidate;
      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());
    }
  }
}








11.19.BufferedOutputStream
11.19.1.BufferedOutputStream
11.19.2.Create DataOutputStream out of BufferedOutputStream
11.19.3.Create DataInputStream out of BufferedInputStream
11.19.4.Write to file using BufferedOutputStream
11.19.5.Write byte array to file using BufferedOutputStream
11.19.6.Write byte to file using BufferedOutputStream
11.19.7.Append string to a text file