/**
* @author lautturi.com
* Java example: byte array to file java
*/
import java.util.*;
import java.time.*;
import java.io.*;
public class Lautturi {
public static void main(String[] args) {
String str = "Hello";
byte[] myByteArray = str.getBytes();
try (FileOutputStream fos = new FileOutputStream("test.txt")) {
fos.write(myByteArray);
// fos.close(); //We create an instance of "fos" inside the try, It will automatically close the OutputStream
} catch (IOException e) {
e.printStackTrace();
}
}
}
open the file test.txt:
Hello