Java Files write byte array to a file
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class Main { public static void main(String[] args) { Path path = Paths.get("Main.java"); try {/* ww w. j av a 2s .c om*/ byte[] contents = "demo2s.com".getBytes(); Files.write(path, contents, StandardOpenOption.CREATE); } catch (IOException e) { e.printStackTrace(); } } }