Save the bytes to a file in Java

Description

The following code shows how to save the bytes to a file.

Example


/*w  ww .  j av  a  2 s.  c o  m*/
import java.io.FileOutputStream;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] vals = { 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 };
    FileOutputStream fout = new FileOutputStream("Test.dat");
    for (int i = 0; i < vals.length; i += 2)
      fout.write(vals[i]);
    fout.close();
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip