Write byte array to a file using FileOutputStream in Java

Description

The following code shows how to write byte array to a file using FileOutputStream.

Example


// w w  w.  j  a  v  a 2 s.  c  o m
import java.io.FileOutputStream;

public class Main {
  public static void main(String[] args) throws Exception {
    String strFilePath = "test.txt";
    FileOutputStream fos = new FileOutputStream(strFilePath);
    String strContent = "Write File from java2s.com!";
    fos.write(strContent.getBytes());
    fos.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