Java I/O How to - Write byte to a file








Question

We would like to know how to write byte to a file.

Answer

import java.io.FileOutputStream;
/*from  w w  w  .  j a  v a 2s. c o  m*/
public class Main {

  public static void main(String[] args) throws Exception {
    FileOutputStream fos = new FileOutputStream("C:/demo.txt");

    byte b = 01;
    fos.write(b);
    fos.close();
  }
}